5555from .watchlog import WatchLog
5656
5757
58+ AUTO_LOOPBACK_IPV4_BASE = ipaddress .ip_interface ("10.255.0.0/32" )
59+ AUTO_LOOPBACK_IPV6_BASE = ipaddress .ip_interface ("fcfe::0/128" )
60+
61+
5862class L3ContainerNotRunningError (MunetError ):
5963 """Exception if no running container exists."""
6064
@@ -63,16 +67,14 @@ def get_loopback_ips(c, nid):
6367 ips = []
6468 if ip := c .get ("ip" ):
6569 if ip == "auto" :
66- assert nid < 0xFFFF # Limited to 10.255.0.0/16 block
67- ips .append (ipaddress .ip_interface ("10.255.0.0/32" ) + nid )
70+ ips .append (AUTO_LOOPBACK_IPV4_BASE + nid )
6871 elif isinstance (ip , str ):
6972 ips .append (ipaddress .ip_interface (ip ))
7073 else :
7174 ips .extend ([ipaddress .ip_interface (x ) for x in ip ])
7275 if ipv6 := c .get ("ipv6" ):
7376 if ipv6 == "auto" :
74- assert nid < 0xFFFF # Same limit as ipv4 for simplicity
75- ips .append (ipaddress .ip_interface (f"fcfe:ffff:{ nid :02x} ::1/128" ))
77+ ips .append (AUTO_LOOPBACK_IPV6_BASE + nid )
7678 elif isinstance (ip , str ):
7779 ips .append (ipaddress .ip_interface (ipv6 ))
7880 else :
@@ -797,9 +799,13 @@ def __init__(self, *args, unet=None, **kwargs):
797799 )
798800 self .next_p2p_network6 = ipaddress .ip_network (f"fcff:ffff:{ self .id :02x} ::/127" )
799801
800- if "ip" not in self .config and self .unet .autonumber :
802+ if "ip" not in self .config and self .unet .autonumber_loopbacks :
801803 self .config ["ip" ] = "auto"
802- if "ipv6" not in self .config and self .unet .autonumber and self .unet .ipv6_enable :
804+ if (
805+ "ipv6" not in self .config
806+ and self .unet .autonumber_loopbacks
807+ and self .unet .ipv6_enable
808+ ):
803809 self .config ["ipv6" ] = "auto"
804810 self .loopback_ip = None
805811 self .loopback_ips = get_loopback_ips (self .config , self .id )
@@ -3304,6 +3310,14 @@ def autonumber(self):
33043310 def autonumber (self , value ):
33053311 self .topoconf ["networks-autonumber" ] = bool (value )
33063312
3313+ @property
3314+ def autonumber_loopbacks (self ):
3315+ return self .topoconf .get ("loopbacks-autonumber" , False )
3316+
3317+ @autonumber_loopbacks .setter
3318+ def autonumber_loopbacks (self , value ):
3319+ self .topoconf ["loopbacks-autonumber" ] = bool (value )
3320+
33073321 async def add_dummy_link (self , node1 , c1 = None ):
33083322 c1 = {} if c1 is None else c1
33093323
0 commit comments