@@ -59,13 +59,24 @@ class L3ContainerNotRunningError(MunetError):
5959
6060
6161def get_loopback_ips (c , nid ):
62+ ips = []
6263 if ip := c .get ("ip" ):
6364 if ip == "auto" :
64- return [ipaddress .ip_interface ("10.255.0.0/32" ) + nid ]
65- if isinstance (ip , str ):
66- return [ipaddress .ip_interface (ip )]
67- return [ipaddress .ip_interface (x ) for x in ip ]
68- return []
65+ assert nid < 0xFFFF # Limited to 10.255.0.0/16 block
66+ ips .append (ipaddress .ip_interface ("10.255.0.0/32" ) + nid )
67+ elif isinstance (ip , str ):
68+ ips .append (ipaddress .ip_interface (ip ))
69+ else :
70+ ips .extend ([ipaddress .ip_interface (x ) for x in ip ])
71+ if ipv6 := c .get ("ipv6" ):
72+ if ipv6 == "auto" :
73+ assert nid < 0xFFFF # Same limit as ipv4 for simplicity
74+ ips .append (ipaddress .ip_interface (f"fcfe:ffff:{ nid :02x} ::1/128" ))
75+ elif isinstance (ip , str ):
76+ ips .append (ipaddress .ip_interface (ipv6 ))
77+ else :
78+ ips .extend ([ipaddress .ip_interface (x ) for x in ipv6 ])
79+ return ips
6980
7081
7182def make_ip_network (net , inc ):
@@ -94,6 +105,7 @@ def get_ip_network(c, brid, ipv6=False):
94105 return ifip
95106 except ValueError :
96107 return ipaddress .ip_network (ip )
108+ assert brid < 0xFDFF # Limited to 10.0.0.0/16 through 10.253.0.0/16 blocks
97109 if ipv6 :
98110 return make_ip_interface ("fc00::fe/64" , brid )
99111 return make_ip_interface ("10.0.0.254/24" , brid )
@@ -779,12 +791,16 @@ def __init__(self, *args, unet=None, **kwargs):
779791 self .cmd_raises ("sysctl -w net.ipv6.conf.all.disable_ipv6=0" )
780792 self .cmd_raises ("sysctl -w net.ipv6.conf.all.forwarding=1" )
781793
782- assert self .id < 0xFF * ( 0xFF - 0x7F ) # Beyond this, ipv4 address is invalid
794+ assert self .id < 0x7FFF # Limited to 10.254.0.0/16 block
783795 self .next_p2p_network = ipaddress .ip_network (
784796 f"10.254.{ self .id & 0xFF } .{ (self .id & 0x7F00 ) >> 7 } /31"
785797 )
786798 self .next_p2p_network6 = ipaddress .ip_network (f"fcff:ffff:{ self .id :02x} ::/127" )
787799
800+ if "ip" not in self .config and self .unet .autonumber :
801+ self .config ["ip" ] = "auto"
802+ if "ipv6" not in self .config and self .unet .autonumber and self .unet .ipv6_enable :
803+ self .config ["ipv6" ] = "auto"
788804 self .loopback_ip = None
789805 self .loopback_ips = get_loopback_ips (self .config , self .id )
790806 self .loopback_ip = self .loopback_ips [0 ] if self .loopback_ips else None
0 commit comments