@@ -57,6 +57,7 @@ type iptablesCleanFuncs []iptableCleanFunc
5757type configuration struct {
5858 EnableIPForwarding bool
5959 EnableIPTables bool
60+ EnableIP6Tables bool
6061 EnableUserlandProxy bool
6162 UserlandProxyPath string
6263}
@@ -133,22 +134,27 @@ type bridgeNetwork struct {
133134 config * networkConfiguration
134135 endpoints map [string ]* bridgeEndpoint // key: endpoint id
135136 portMapper * portmapper.PortMapper
137+ portMapperV6 * portmapper.PortMapper
136138 driver * driver // The network's driver
137139 iptCleanFuncs iptablesCleanFuncs
138140 sync.Mutex
139141}
140142
141143type driver struct {
142- config * configuration
143- network * bridgeNetwork
144- natChain * iptables.ChainInfo
145- filterChain * iptables.ChainInfo
146- isolationChain1 * iptables.ChainInfo
147- isolationChain2 * iptables.ChainInfo
148- networks map [string ]* bridgeNetwork
149- store datastore.DataStore
150- nlh * netlink.Handle
151- configNetwork sync.Mutex
144+ config * configuration
145+ network * bridgeNetwork
146+ natChain * iptables.ChainInfo
147+ filterChain * iptables.ChainInfo
148+ isolationChain1 * iptables.ChainInfo
149+ isolationChain2 * iptables.ChainInfo
150+ natChainV6 * iptables.ChainInfo
151+ filterChainV6 * iptables.ChainInfo
152+ isolationChain1V6 * iptables.ChainInfo
153+ isolationChain2V6 * iptables.ChainInfo
154+ networks map [string ]* bridgeNetwork
155+ store datastore.DataStore
156+ nlh * netlink.Handle
157+ configNetwork sync.Mutex
152158 sync.Mutex
153159}
154160
@@ -277,14 +283,18 @@ func (n *bridgeNetwork) registerIptCleanFunc(clean iptableCleanFunc) {
277283 n .iptCleanFuncs = append (n .iptCleanFuncs , clean )
278284}
279285
280- func (n * bridgeNetwork ) getDriverChains () (* iptables.ChainInfo , * iptables.ChainInfo , * iptables.ChainInfo , * iptables.ChainInfo , error ) {
286+ func (n * bridgeNetwork ) getDriverChains (version iptables. IPVersion ) (* iptables.ChainInfo , * iptables.ChainInfo , * iptables.ChainInfo , * iptables.ChainInfo , error ) {
281287 n .Lock ()
282288 defer n .Unlock ()
283289
284290 if n .driver == nil {
285291 return nil , nil , nil , nil , types .BadRequestErrorf ("no driver found" )
286292 }
287293
294+ if version == iptables .IPv6 {
295+ return n .driver .natChainV6 , n .driver .filterChainV6 , n .driver .isolationChain1V6 , n .driver .isolationChain2V6 , nil
296+ }
297+
288298 return n .driver .natChain , n .driver .filterChain , n .driver .isolationChain1 , n .driver .isolationChain2 , nil
289299}
290300
@@ -323,17 +333,31 @@ func (n *bridgeNetwork) isolateNetwork(others []*bridgeNetwork, enable bool) err
323333 }
324334
325335 // Install the rules to isolate this network against each of the other networks
326- return setINC (thisConfig .BridgeName , enable )
336+ if n .driver .config .EnableIP6Tables {
337+ err := setINC (iptables .IPv6 , thisConfig .BridgeName , enable )
338+ if err != nil {
339+ return err
340+ }
341+ }
342+
343+ if n .driver .config .EnableIPTables {
344+ return setINC (iptables .IPv4 , thisConfig .BridgeName , enable )
345+ }
346+ return nil
327347}
328348
329349func (d * driver ) configure (option map [string ]interface {}) error {
330350 var (
331- config * configuration
332- err error
333- natChain * iptables.ChainInfo
334- filterChain * iptables.ChainInfo
335- isolationChain1 * iptables.ChainInfo
336- isolationChain2 * iptables.ChainInfo
351+ config * configuration
352+ err error
353+ natChain * iptables.ChainInfo
354+ filterChain * iptables.ChainInfo
355+ isolationChain1 * iptables.ChainInfo
356+ isolationChain2 * iptables.ChainInfo
357+ natChainV6 * iptables.ChainInfo
358+ filterChainV6 * iptables.ChainInfo
359+ isolationChain1V6 * iptables.ChainInfo
360+ isolationChain2V6 * iptables.ChainInfo
337361 )
338362
339363 genericData , ok := option [netlabel .GenericData ]
@@ -354,23 +378,46 @@ func (d *driver) configure(option map[string]interface{}) error {
354378 return & ErrInvalidDriverConfig {}
355379 }
356380
357- if config .EnableIPTables {
381+ if config .EnableIPTables || config . EnableIP6Tables {
358382 if _ , err := os .Stat ("/proc/sys/net/bridge" ); err != nil {
359383 if out , err := exec .Command ("modprobe" , "-va" , "bridge" , "br_netfilter" ).CombinedOutput (); err != nil {
360384 logrus .Warnf ("Running modprobe bridge br_netfilter failed with message: %s, error: %v" , out , err )
361385 }
362386 }
363- removeIPChains ()
364- natChain , filterChain , isolationChain1 , isolationChain2 , err = setupIPChains (config )
387+ }
388+
389+ if config .EnableIPTables {
390+ removeIPChains (iptables .IPv4 )
391+
392+ natChain , filterChain , isolationChain1 , isolationChain2 , err = setupIPChains (config , iptables .IPv4 )
393+ if err != nil {
394+ return err
395+ }
396+
397+ // Make sure on firewall reload, first thing being re-played is chains creation
398+ iptables .OnReloaded (func () {
399+ logrus .Debugf ("Recreating iptables chains on firewall reload" )
400+ setupIPChains (config , iptables .IPv4 )
401+ })
402+ }
403+
404+ if config .EnableIP6Tables {
405+ removeIPChains (iptables .IPv6 )
406+
407+ natChainV6 , filterChainV6 , isolationChain1V6 , isolationChain2V6 , err = setupIPChains (config , iptables .IPv6 )
365408 if err != nil {
366409 return err
367410 }
411+
368412 // Make sure on firewall reload, first thing being re-played is chains creation
369- iptables .OnReloaded (func () { logrus .Debugf ("Recreating iptables chains on firewall reload" ); setupIPChains (config ) })
413+ iptables .OnReloaded (func () {
414+ logrus .Debugf ("Recreating ip6tables chains on firewall reload" )
415+ setupIPChains (config , iptables .IPv6 )
416+ })
370417 }
371418
372419 if config .EnableIPForwarding {
373- err = setupIPForwarding (config .EnableIPTables )
420+ err = setupIPForwarding (config .EnableIPTables , config . EnableIP6Tables )
374421 if err != nil {
375422 logrus .Warn (err )
376423 return err
@@ -382,6 +429,10 @@ func (d *driver) configure(option map[string]interface{}) error {
382429 d .filterChain = filterChain
383430 d .isolationChain1 = isolationChain1
384431 d .isolationChain2 = isolationChain2
432+ d .natChainV6 = natChainV6
433+ d .filterChainV6 = filterChainV6
434+ d .isolationChain1V6 = isolationChain1V6
435+ d .isolationChain2V6 = isolationChain2V6
385436 d .config = config
386437 d .Unlock ()
387438
@@ -644,12 +695,13 @@ func (d *driver) createNetwork(config *networkConfiguration) (err error) {
644695
645696 // Create and set network handler in driver
646697 network := & bridgeNetwork {
647- id : config .ID ,
648- endpoints : make (map [string ]* bridgeEndpoint ),
649- config : config ,
650- portMapper : portmapper .New (d .config .UserlandProxyPath ),
651- bridge : bridgeIface ,
652- driver : d ,
698+ id : config .ID ,
699+ endpoints : make (map [string ]* bridgeEndpoint ),
700+ config : config ,
701+ portMapper : portmapper .New (d .config .UserlandProxyPath ),
702+ portMapperV6 : portmapper .New (d .config .UserlandProxyPath ),
703+ bridge : bridgeIface ,
704+ driver : d ,
653705 }
654706
655707 d .Lock ()
@@ -724,11 +776,16 @@ func (d *driver) createNetwork(config *networkConfiguration) (err error) {
724776 {! d .config .EnableUserlandProxy , setupLoopbackAddressesRouting },
725777
726778 // Setup IPTables.
727- {d .config .EnableIPTables , network .setupIPTables },
779+ {d .config .EnableIPTables , network .setupIP4Tables },
780+
781+ // Setup IP6Tables.
782+ {d .config .EnableIP6Tables , network .setupIP6Tables },
728783
729784 //We want to track firewalld configuration so that
730785 //if it is started/reloaded, the rules can be applied correctly
731786 {d .config .EnableIPTables , network .setupFirewalld },
787+ // same for IPv6
788+ {d .config .EnableIP6Tables , network .setupFirewalld6 },
732789
733790 // Setup DefaultGatewayIPv4
734791 {config .DefaultGatewayIPv4 != nil , setupGatewayIPv4 },
0 commit comments