3 # Copyright 2014-2017 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
9 from ipaddr
import IPNetwork
, IPv4Network
, IPv6Network
, _BaseV6
12 from ifupdown2
.ifupdown
.iface
import *
13 from ifupdown2
.ifupdown
.utils
import utils
14 from ifupdown2
.ifupdown
.netlink
import netlink
16 from ifupdown2
.ifupdownaddons
.dhclient
import dhclient
17 from ifupdown2
.ifupdownaddons
.LinkUtils
import LinkUtils
18 from ifupdown2
.ifupdownaddons
.modulebase
import moduleBase
20 import ifupdown2
.ifupdown
.statemanager
as statemanager
21 import ifupdown2
.ifupdown
.policymanager
as policymanager
22 import ifupdown2
.ifupdown
.ifupdownflags
as ifupdownflags
23 import ifupdown2
.ifupdown
.ifupdownconfig
as ifupdownconfig
25 from ifupdown
.iface
import *
26 from ifupdown
.utils
import utils
27 from ifupdown
.netlink
import netlink
29 from ifupdownaddons
.dhclient
import dhclient
30 from ifupdownaddons
.LinkUtils
import LinkUtils
31 from ifupdownaddons
.modulebase
import moduleBase
33 import ifupdown
.statemanager
as statemanager
34 import ifupdown
.policymanager
as policymanager
35 import ifupdown
.ifupdownflags
as ifupdownflags
36 import ifupdown
.ifupdownconfig
as ifupdownconfig
39 class address(moduleBase
):
40 """ ifupdown2 addon module to configure address, mtu, hwaddress, alias
41 (description) on an interface """
43 _modinfo
= {'mhelp' : 'address configuration module for interfaces',
46 {'help' : 'ipv4 or ipv6 addresses',
47 'validvals' : ['<ipv4/prefixlen>', '<ipv6/prefixlen>'],
49 'example' : ['address 10.0.12.3/24',
50 'address 2000:1000:1000:1000:3::5/128']},
53 'example' : ['netmask 255.255.255.0'],
56 {'help': 'broadcast address',
57 'validvals' : ['<ipv4>', ],
58 'example' : ['broadcast 10.0.1.255']},
61 'validvals' : ['universe', 'site', 'link', 'host', 'nowhere'],
62 'example' : ['scope host']},
63 'preferred-lifetime' :
64 {'help': 'preferred lifetime',
65 'validrange' : ['0', '65535'],
66 'example' : ['preferred-lifetime forever',
67 'preferred-lifetime 10']},
69 {'help': 'default gateway',
70 'validvals' : ['<ipv4>', '<ipv6>'],
72 'example' : ['gateway 255.255.255.0']},
74 { 'help': 'interface mtu',
75 'validrange' : ['552', '9216'],
76 'example' : ['mtu 1600'],
79 {'help' : 'hw address',
80 'validvals' : ['<mac>',],
81 'example': ['hwaddress 44:38:39:00:27:b8']},
83 { 'help': 'description/alias',
84 'example' : ['alias testnetwork']},
86 { 'help': 'purge existing addresses. By default ' +
87 'any existing ip addresses on an interface are ' +
88 'purged to match persistant addresses in the ' +
89 'interfaces file. Set this attribute to \'no\'' +
90 'if you want to preserve existing addresses',
91 'validvals' : ['yes', 'no'],
93 'example' : ['address-purge yes/no']},
94 'clagd-vxlan-anycast-ip' :
95 { 'help' : 'Anycast local IP address for ' +
96 'dual connected VxLANs',
97 'validvals' : ['<ipv4>', ],
98 'example' : ['clagd-vxlan-anycast-ip 36.0.0.11']},
100 { 'help': 'ip forwarding flag',
101 'validvals': ['on', 'off', 'yes', 'no', '0', '1'],
103 'example' : ['ip-forward off']},
105 { 'help': 'ipv6 forwarding flag',
106 'validvals': ['on', 'off', 'yes', 'no', '0', '1'],
108 'example' : ['ip6-forward off']},
110 { 'help': 'mpls enable flag',
111 'validvals': ['yes', 'no'],
113 'example' : ['mpls-enable yes']},
115 'help': 'enable disable ipv6 link addrgenmode',
116 'validvals': ['on', 'off'],
125 def __init__(self
, *args
, **kargs
):
126 moduleBase
.__init
__(self
, *args
, **kargs
)
128 self
._bridge
_fdb
_query
_cache
= {}
129 self
.default_mtu
= policymanager
.policymanager_api
.get_attr_default(module_name
=self
.__class
__.__name
__, attr
='mtu')
130 self
.max_mtu
= policymanager
.policymanager_api
.get_module_globals(module_name
=self
.__class
__.__name
__, attr
='max_mtu')
131 self
.ipforward
= policymanager
.policymanager_api
.get_attr_default(module_name
=self
.__class
__.__name
__, attr
='ip-forward')
132 self
.ip6forward
= policymanager
.policymanager_api
.get_attr_default(module_name
=self
.__class
__.__name
__, attr
='ip6-forward')
133 self
.ifaces_defaults
= policymanager
.policymanager_api
.get_iface_defaults(module_name
=self
.__class
__.__name
__)
134 self
.enable_l3_iface_forwarding_checks
= utils
.get_boolean_from_string(
135 policymanager
.policymanager_api
.get_module_globals(
136 self
.__class
__.__name
__,
137 'enable_l3_iface_forwarding_checks'
141 if not self
.default_mtu
:
142 self
.default_mtu
= '1500'
144 self
.logger
.info('address: using default mtu %s' %self
.default_mtu
)
147 self
.logger
.info('address: using max mtu %s' %self
.max_mtu
)
149 self
.lower_iface_mtu_checked_list
= list()
151 self
.l3_intf_arp_accept
= utils
.get_boolean_from_string(
152 policymanager
.policymanager_api
.get_module_globals(
153 module_name
=self
.__class
__.__name
__,
154 attr
='l3_intf_arp_accept'
159 self
.l3_intf_default_gateway_set_onlink
= utils
.get_boolean_from_string(
160 policymanager
.policymanager_api
.get_module_globals(
161 module_name
=self
.__class
__.__name
__,
162 attr
='l3_intf_default_gateway_set_onlink'
167 def syntax_check(self
, ifaceobj
, ifaceobj_getfunc
=None):
168 return (self
.syntax_check_multiple_gateway(ifaceobj
)
169 and self
.syntax_check_addr_allowed_on(ifaceobj
, True)
170 and self
.syntax_check_mtu(ifaceobj
, ifaceobj_getfunc
)
171 and self
.syntax_check_sysctls(ifaceobj
)
172 and self
.syntax_check_enable_l3_iface_forwardings(ifaceobj
, ifaceobj_getfunc
, syntax_check
=True))
174 def syntax_check_enable_l3_iface_forwardings(self
, ifaceobj
, ifaceobj_getfunc
, syntax_check
=False):
175 if (self
.enable_l3_iface_forwarding_checks
176 and (ifaceobj
.link_kind
& ifaceLinkKind
.VLAN
177 or ifaceobj
.link_kind
& ifaceLinkKind
.BRIDGE
)
178 and not ifaceobj
.link_privflags
& ifaceLinkPrivFlags
.BRIDGE_PORT
):
180 ifname
= ifaceobj
.name
182 vlan_ipforward_off
= None
184 for obj
in ifaceobj_getfunc(ifname
) or [ifaceobj
]:
186 vlan_addr
= obj
.get_attr_value('address')
188 if not vlan_ipforward_off
:
189 ip_forward_value
= obj
.get_attr_value_first('ip-forward')
191 if ip_forward_value
and not utils
.get_boolean_from_string(ip_forward_value
):
192 vlan_ipforward_off
= True
194 if vlan_addr
and vlan_ipforward_off
:
197 'configuring ip-forward off and ip address(es) (%s) is not compatible'
198 % (', '.join(vlan_addr
))
202 '%s: configuring ip-forward off and ip address(es) (%s) is not compatible'
203 % (ifname
, ', '.join(vlan_addr
))
208 def syntax_check_sysctls(self
, ifaceobj
):
210 bridge_port
= (ifaceobj
.link_privflags
& ifaceLinkPrivFlags
.BRIDGE_PORT
)
211 ipforward
= ifaceobj
.get_attr_value_first('ip-forward')
212 if bridge_port
and ipforward
:
214 self
.log_error('%s: \'ip-forward\' is not supported for '
215 'bridge port' %ifaceobj
.name
)
216 ip6forward
= ifaceobj
.get_attr_value_first('ip6-forward')
217 if bridge_port
and ip6forward
:
219 self
.log_error('%s: \'ip6-forward\' is not supported for '
220 'bridge port' %ifaceobj
.name
)
223 def syntax_check_mtu(self
, ifaceobj
, ifaceobj_getfunc
):
224 mtu
= ifaceobj
.get_attr_value_first('mtu')
226 return self
._check
_mtu
_config
(ifaceobj
, mtu
, ifaceobj_getfunc
,
230 def syntax_check_addr_allowed_on(self
, ifaceobj
, syntax_check
=False):
231 if ifaceobj
.get_attr_value('address'):
232 return utils
.is_addr_ip_allowed_on(ifaceobj
, syntax_check
=syntax_check
)
235 def _syntax_check_multiple_gateway(self
, family
, found
, addr
, type_obj
):
236 if type(IPNetwork(addr
)) == type_obj
:
238 raise Exception('%s: multiple gateways for %s family'
243 def syntax_check_multiple_gateway(self
, ifaceobj
):
247 gateways
= ifaceobj
.get_attr_value('gateway')
248 for addr
in gateways
if gateways
else []:
250 if self
._syntax
_check
_multiple
_gateway
('inet', inet
, addr
,
253 if self
._syntax
_check
_multiple
_gateway
('inet6', inet6
, addr
,
256 except Exception as e
:
257 self
.logger
.warning('%s: address: %s' % (ifaceobj
.name
, str(e
)))
261 def _address_valid(self
, addrs
):
264 if any(map(lambda a
: True if a
[:7] != '0.0.0.0'
269 def _get_hwaddress(self
, ifaceobj
):
270 return utils
.strip_hwaddress(ifaceobj
.get_attr_value_first('hwaddress'))
272 def _process_bridge(self
, ifaceobj
, up
):
273 hwaddress
= self
._get
_hwaddress
(ifaceobj
)
274 addrs
= ifaceobj
.get_attr_value_first('address')
275 is_vlan_dev_on_vlan_aware_bridge
= False
276 is_bridge
= self
.ipcmd
.is_bridge(ifaceobj
.name
)
278 if ifaceobj
.link_kind
& ifaceLinkKind
.VLAN
:
279 bridgename
= ifaceobj
.lowerifaces
[0]
280 vlan
= self
._get
_vlan
_id
(ifaceobj
)
281 is_vlan_dev_on_vlan_aware_bridge
= self
.ipcmd
.bridge_is_vlan_aware(bridgename
)
282 if ((is_bridge
and not self
.ipcmd
.bridge_is_vlan_aware(ifaceobj
.name
))
283 or is_vlan_dev_on_vlan_aware_bridge
):
284 if self
._address
_valid
(addrs
):
285 if self
.l3_intf_arp_accept
:
287 self
.write_file('/proc/sys/net/ipv4/conf/%s' % ifaceobj
.name
+
290 self
.write_file('/proc/sys/net/ipv4/conf/%s' % ifaceobj
.name
+
293 self
.write_file('/proc/sys/net/ipv4/conf/%s/arp_accept' % ifaceobj
.name
, '0')
294 if hwaddress
and is_vlan_dev_on_vlan_aware_bridge
:
296 self
.ipcmd
.bridge_fdb_add(bridgename
, hwaddress
, vlan
)
298 self
.ipcmd
.bridge_fdb_del(bridgename
, hwaddress
, vlan
)
300 def _get_anycast_addr(self
, ifaceobjlist
):
301 for ifaceobj
in ifaceobjlist
:
302 anycast_addr
= ifaceobj
.get_attr_value_first('clagd-vxlan-anycast-ip')
304 anycast_addr
= anycast_addr
+'/32'
308 def _inet_address_convert_to_cidr(self
, ifaceobjlist
):
312 for ifaceobj
in ifaceobjlist
:
313 addrs
= ifaceobj
.get_attr_value('address')
317 if not self
.syntax_check_addr_allowed_on(ifaceobj
,
319 return (False, newaddrs
, newaddr_attrs
)
320 # If user address is not in CIDR notation, convert them to CIDR
321 for addr_index
in range(0, len(addrs
)):
322 addr
= addrs
[addr_index
]
325 newaddrs
.append(addr
)
327 netmask
= ifaceobj
.get_attr_value_n('netmask', addr_index
)
329 prefixlen
= IPNetwork('%s' %addr
+
330 '/%s' %netmask
).prefixlen
331 newaddr
= addr
+ '/%s' %prefixlen
333 # we are here because there is no slash (/xx) and no netmask
334 # just let IPNetwork handle the ipv4 or ipv6 address mask
335 prefixlen
= IPNetwork(addr
).prefixlen
336 newaddr
= addr
+ '/%s' %prefixlen
337 newaddrs
.append(newaddr
)
340 for a
in ['broadcast', 'pointopoint', 'scope',
341 'preferred-lifetime']:
342 aval
= ifaceobj
.get_attr_value_n(a
, addr_index
)
347 newaddr_attrs
[newaddr
]= attrs
348 return (True, newaddrs
, newaddr_attrs
)
350 def _inet_address_list_config(self
, ifaceobj
, newaddrs
, newaddr_attrs
):
351 for addr_index
in range(0, len(newaddrs
)):
354 self
.ipcmd
.addr_add(ifaceobj
.name
, newaddrs
[addr_index
],
355 newaddr_attrs
.get(newaddrs
[addr_index
],
356 {}).get('broadcast'),
357 newaddr_attrs
.get(newaddrs
[addr_index
],
358 {}).get('pointopoint'),
359 newaddr_attrs
.get(newaddrs
[addr_index
],
361 newaddr_attrs
.get(newaddrs
[addr_index
],
362 {}).get('preferred-lifetime'))
364 self
.ipcmd
.addr_add(ifaceobj
.name
, newaddrs
[addr_index
])
366 self
.log_error(str(e
), ifaceobj
)
368 def _inet_address_config(self
, ifaceobj
, ifaceobj_getfunc
=None,
369 force_reapply
=False):
370 squash_addr_config
= (True if \
371 ifupdownconfig
.config
.get('addr_config_squash', \
372 '0') == '1' else False)
374 if (squash_addr_config
and
375 not (ifaceobj
.flags
& ifaceobj
.YOUNGEST_SIBLING
)):
378 purge_addresses
= ifaceobj
.get_attr_value_first('address-purge')
379 if not purge_addresses
:
380 purge_addresses
= 'yes'
382 if squash_addr_config
and ifaceobj
.flags
& iface
.HAS_SIBLINGS
:
383 ifaceobjlist
= ifaceobj_getfunc(ifaceobj
.name
)
385 ifaceobjlist
= [ifaceobj
]
387 module_name
= self
.__class
__.__name
__
388 ifname
= ifaceobj
.name
390 (addr_supported
, newaddrs
, newaddr_attrs
) = self
._inet
_address
_convert
_to
_cidr
(ifaceobjlist
)
391 newaddrs
= utils
.get_ip_objs(module_name
, ifname
, newaddrs
)
393 if not addr_supported
:
395 if (not squash_addr_config
and (ifaceobj
.flags
& iface
.HAS_SIBLINGS
)):
396 # if youngest sibling and squash addr is not set
397 # print a warning that addresses will not be purged
398 if (ifaceobj
.flags
& iface
.YOUNGEST_SIBLING
):
399 self
.logger
.warn('%s: interface has multiple ' %ifaceobj
.name
+
400 'iface stanzas, skip purging existing addresses')
401 purge_addresses
= 'no'
403 if not ifupdownflags
.flags
.PERFMODE
and purge_addresses
== 'yes':
404 # if perfmode is not set and purge addresses is not set to 'no'
405 # lets purge addresses not in the config
406 runningaddrs
= self
.ipcmd
.get_running_addrs(ifaceobj
, details
=False)
408 # if anycast address is configured on 'lo' and is in running config
409 # add it to newaddrs so that ifreload doesn't wipe it out
410 anycast_addr
= utils
.get_normalized_ip_addr(ifaceobj
.name
, self
._get
_anycast
_addr
(ifaceobjlist
))
412 if runningaddrs
and anycast_addr
and anycast_addr
in runningaddrs
:
413 newaddrs
.append(anycast_addr
)
415 user_ip4
, user_ip6
, newaddrs
= self
.order_user_configured_addrs(newaddrs
)
417 if newaddrs
== runningaddrs
or self
.compare_running_ips_and_user_config(user_ip4
, user_ip6
, runningaddrs
):
419 self
._inet
_address
_list
_config
(ifaceobj
, newaddrs
, newaddr_attrs
)
422 # if primary address is not same, there is no need to keep any.
423 # reset all addresses
424 if newaddrs
and runningaddrs
and newaddrs
[0] != runningaddrs
[0]:
427 skip_addrs
= newaddrs
or []
428 for addr
in runningaddrs
or []:
429 if addr
in skip_addrs
:
431 self
.ipcmd
.addr_del(ifaceobj
.name
, addr
)
433 self
.log_warn(str(e
))
436 self
._inet
_address
_list
_config
(ifaceobj
, newaddrs
, newaddr_attrs
)
438 def compare_running_ips_and_user_config(self
, user_ip4
, user_ip6
, running_addrs
):
440 We need to compare the user config ips and the running ips.
441 ip4 ordering matters (primary etc) but ip6 order doesn't matter
443 this function replaces the strict comparison previously in place
444 if newaddrs == running_addrs ?
446 We will compare if the ip4 ordering is correct, then check if all
447 ip6 are present in the list (without checking the ordering)
449 if (user_ip4
or user_ip6
) and not running_addrs
:
451 elif running_addrs
and not user_ip4
and not user_ip6
:
453 elif not running_addrs
and not user_ip4
and not user_ip6
:
456 len_ip4
= len(user_ip4
)
457 len_running_addrs
= len(running_addrs
)
459 if len_ip4
> len_running_addrs
:
464 if user_ip4
[i
] != running_addrs
[i
]:
469 running_ip6
= running_addrs
[len_ip4
:]
471 running_ip6
= running_addrs
474 len_ip6
= len(user_ip6
)
476 for ip6
in running_ip6
:
477 if ip6
not in user_ip6
:
483 def order_user_configured_addrs(self
, user_config_addrs
):
487 for a
in user_config_addrs
:
488 if isinstance(a
, _BaseV6
):
493 return ip4
, ip6
, ip4
+ ip6
495 def _delete_gateway(self
, ifaceobj
, gateways
, vrf
, metric
):
496 for del_gw
in gateways
:
498 self
.ipcmd
.route_del_gateway(ifaceobj
.name
, del_gw
, vrf
, metric
)
499 except Exception as e
:
500 self
.logger
.debug('%s: %s' % (ifaceobj
.name
, str(e
)))
502 def _add_delete_gateway(self
, ifaceobj
, gateways
=[], prev_gw
=[]):
503 vrf
= ifaceobj
.get_attr_value_first('vrf')
504 metric
= ifaceobj
.get_attr_value_first('metric')
505 self
._delete
_gateway
(ifaceobj
, list(set(prev_gw
) - set(gateways
)),
507 for add_gw
in gateways
:
509 self
.ipcmd
.route_add_gateway(ifaceobj
.name
, add_gw
, vrf
, metric
, onlink
=self
.l3_intf_default_gateway_set_onlink
)
510 except Exception as e
:
511 self
.log_error('%s: %s' % (ifaceobj
.name
, str(e
)))
513 def _get_prev_gateway(self
, ifaceobj
, gateways
):
515 saved_ifaceobjs
= statemanager
.statemanager_api
.get_ifaceobjs(ifaceobj
.name
)
516 if not saved_ifaceobjs
:
518 prev_gateways
= saved_ifaceobjs
[0].get_attr_value('gateway')
519 if not prev_gateways
:
523 def _check_mtu_config(self
, ifaceobj
, mtu
, ifaceobj_getfunc
, syntaxcheck
=False):
525 if (ifaceobj
.link_kind
& ifaceLinkKind
.BRIDGE
):
527 self
.logger
.warn('%s: bridge inherits mtu from its ports. There is no need to assign mtu on a bridge' %ifaceobj
.name
)
530 self
.logger
.info('%s: bridge inherits mtu from its ports. There is no need to assign mtu on a bridge' %ifaceobj
.name
)
531 elif ifaceobj_getfunc
:
532 if ((ifaceobj
.link_privflags
& ifaceLinkPrivFlags
.BOND_SLAVE
) and
533 ifaceobj
.upperifaces
):
534 masterobj
= ifaceobj_getfunc(ifaceobj
.upperifaces
[0])
536 master_mtu
= masterobj
[0].get_attr_value_first('mtu')
537 if master_mtu
and master_mtu
!= mtu
:
539 self
.logger
.warn('%s: bond slave mtu %s is different from bond master %s mtu %s. There is no need to configure mtu on a bond slave.' %(ifaceobj
.name
, mtu
, masterobj
[0].name
, master_mtu
))
542 self
.logger
.info('%s: bond slave mtu %s is different from bond master %s mtu %s. There is no need to configure mtu on a bond slave.' %(ifaceobj
.name
, mtu
, masterobj
[0].name
, master_mtu
))
543 elif ((ifaceobj
.link_kind
& ifaceLinkKind
.VLAN
) and
544 ifaceobj
.lowerifaces
):
545 lowerobj
= ifaceobj_getfunc(ifaceobj
.lowerifaces
[0])
548 lowerdev_mtu
= lowerobj
[0].get_attr_value_first('mtu')
550 lowerdev_mtu
= self
.ipcmd
.link_get_mtu_sysfs(lowerobj
[0].name
)
551 if lowerdev_mtu
and int(mtu
) > int(lowerdev_mtu
):
552 self
.logger
.warn('%s: vlan dev mtu %s is greater than lower realdev %s mtu %s'
553 %(ifaceobj
.name
, mtu
, lowerobj
[0].name
, lowerdev_mtu
))
555 elif (not lowerobj
[0].link_kind
and
556 not (lowerobj
[0].link_privflags
& ifaceLinkPrivFlags
.LOOPBACK
) and
557 not lowerdev_mtu
and self
.default_mtu
and
558 (int(mtu
) > int(self
.default_mtu
))):
559 # only check default mtu on lower device which is a physical interface
560 self
.logger
.warn('%s: vlan dev mtu %s is greater than lower realdev %s mtu %s'
561 %(ifaceobj
.name
, mtu
, lowerobj
[0].name
, self
.default_mtu
))
563 if self
.max_mtu
and mtu
> self
.max_mtu
:
564 self
.logger
.warn('%s: specified mtu %s is greater than max mtu %s'
565 %(ifaceobj
.name
, mtu
, self
.max_mtu
))
569 def _propagate_mtu_to_upper_devs(self
, ifaceobj
, mtu
, ifaceobj_getfunc
):
570 if (not ifaceobj
.upperifaces
or
571 (ifaceobj
.link_privflags
& ifaceLinkPrivFlags
.BOND_SLAVE
) or
572 (ifaceobj
.link_privflags
& ifaceLinkPrivFlags
.VRF_SLAVE
) or
573 (ifaceobj
.link_privflags
& ifaceLinkPrivFlags
.BRIDGE_PORT
)):
575 for u
in ifaceobj
.upperifaces
:
576 upperobjs
= ifaceobj_getfunc(u
)
578 not (upperobjs
[0].link_kind
& ifaceLinkKind
.VLAN
)):
580 # only adjust mtu for vlan devices on ifaceobj
581 umtu
= upperobjs
[0].get_attr_value_first('mtu')
583 running_mtu
= self
.ipcmd
.link_get_mtu(upperobjs
[0].name
)
584 if not running_mtu
or (running_mtu
!= mtu
):
585 self
.ipcmd
.link_set(u
, 'mtu', mtu
)
587 def _process_mtu_config(self
, ifaceobj
, ifaceobj_getfunc
, mtu
):
589 if not self
._check
_mtu
_config
(ifaceobj
, mtu
, ifaceobj_getfunc
):
591 cached_running_mtu
= self
.ipcmd
.link_get_mtu(ifaceobj
.name
)
592 running_mtu
= self
.ipcmd
.link_get_mtu_sysfs(ifaceobj
.name
)
593 if not running_mtu
or (running_mtu
and running_mtu
!= mtu
):
594 force
= cached_running_mtu
!= running_mtu
595 self
.ipcmd
.link_set(ifaceobj
.name
, 'mtu', mtu
, force
=force
)
596 if (not ifupdownflags
.flags
.ALL
and
597 not ifaceobj
.link_kind
and
598 ifupdownconfig
.config
.get('adjust_logical_dev_mtu', '1') != '0'):
599 # This is additional cost to us, so do it only when
600 # ifupdown2 is called on a particular interface and
601 # it is a physical interface
602 self
._propagate
_mtu
_to
_upper
_devs
(ifaceobj
, mtu
, ifaceobj_getfunc
)
605 if ifaceobj
.link_kind
:
606 # bonds and vxlan devices need an explicit set of mtu.
607 # bridges don't need mtu set
608 if (ifaceobj
.link_kind
& ifaceLinkKind
.BOND
or
609 ifaceobj
.link_kind
& ifaceLinkKind
.VXLAN
):
610 running_mtu
= self
.ipcmd
.link_get_mtu(ifaceobj
.name
)
611 if (self
.default_mtu
and running_mtu
!= self
.default_mtu
):
612 self
.ipcmd
.link_set(ifaceobj
.name
, 'mtu', self
.default_mtu
)
614 if (ifupdownconfig
.config
.get('adjust_logical_dev_mtu', '1') != '0'
615 and ifaceobj
.lowerifaces
):
616 # set vlan interface mtu to lower device mtu
617 if (ifaceobj
.link_kind
& ifaceLinkKind
.VLAN
):
618 lower_iface
= ifaceobj
.lowerifaces
[0]
619 if lower_iface
not in self
.lower_iface_mtu_checked_list
:
620 lower_iface_mtu
= self
.ipcmd
.link_get_mtu_sysfs(lower_iface
)
621 self
.ipcmd
.cache_update([lower_iface
, 'mtu'], lower_iface_mtu
)
622 self
.lower_iface_mtu_checked_list
.append(lower_iface
)
624 lower_iface_mtu
= self
.ipcmd
.link_get_mtu(lower_iface
)
626 if lower_iface_mtu
!= self
.ipcmd
.link_get_mtu_sysfs(ifaceobj
.name
):
627 self
.ipcmd
.link_set_mtu(ifaceobj
.name
, lower_iface_mtu
)
629 elif (not (ifaceobj
.name
== 'lo') and not ifaceobj
.link_kind
and
630 not (ifaceobj
.link_privflags
& ifaceLinkPrivFlags
.BOND_SLAVE
) and
632 # logical devices like bridges and vlan devices rely on mtu
633 # from their lower devices. ie mtu travels from
634 # lower devices to upper devices. For bonds mtu travels from
635 # upper to lower devices. running mtu depends on upper and
636 # lower device mtu. With all this implicit mtu
637 # config by the kernel in play, we try to be cautious here
638 # on which devices we want to reset mtu to default.
639 # essentially only physical interfaces which are not bond slaves
640 running_mtu
= self
.ipcmd
.link_get_mtu(ifaceobj
.name
)
641 if running_mtu
!= self
.default_mtu
:
642 self
.ipcmd
.link_set(ifaceobj
.name
, 'mtu', self
.default_mtu
)
644 def _set_bridge_forwarding(self
, ifaceobj
):
645 """ set ip forwarding to 0 if bridge interface does not have a
647 ifname
= ifaceobj
.name
648 if not ifaceobj
.upperifaces
and not ifaceobj
.get_attr_value('address'):
649 if self
.sysctl_get_forwarding_value_from_proc(ifname
, "ipv4") == '1':
650 self
.sysctl_write_forwarding_value_to_proc(ifname
, "ipv4", 0)
651 if self
.sysctl_get_forwarding_value_from_proc(ifname
, "ipv6") == '1':
652 self
.sysctl_write_forwarding_value_to_proc(ifname
, "ipv6", 0)
654 if self
.sysctl_get_forwarding_value_from_proc(ifname
, "ipv4") == '0':
655 self
.sysctl_write_forwarding_value_to_proc(ifname
, "ipv4", 1)
656 if self
.sysctl_get_forwarding_value_from_proc(ifname
, "ipv6") == '0':
657 self
.sysctl_write_forwarding_value_to_proc(ifname
, "ipv6", 1)
659 def sysctl_get_forwarding_value_from_proc(self
, ifname
, family
):
660 return self
.read_file_oneline("/proc/sys/net/%s/conf/%s/forwarding" % (family
, ifname
))
662 def sysctl_write_forwarding_value_to_proc(self
, ifname
, family
, value
):
663 self
.write_file("/proc/sys/net/%s/conf/%s/forwarding" % (family
, ifname
), "%s\n" % value
)
665 def _sysctl_config(self
, ifaceobj
):
666 setting_default_value
= False
667 mpls_enable
= ifaceobj
.get_attr_value_first('mpls-enable');
669 setting_default_value
= True
670 mpls_enable
= self
.get_mod_subattr('mpls-enable', 'default')
671 mpls_enable
= utils
.boolean_support_binary(mpls_enable
)
672 # File read has been used for better performance
673 # instead of using sysctl command
674 if ifupdownflags
.flags
.PERFMODE
:
675 running_mpls_enable
= '0'
677 running_mpls_enable
= self
.read_file_oneline(
678 '/proc/sys/net/mpls/conf/%s/input'
682 if mpls_enable
!= running_mpls_enable
:
684 self
.sysctl_set('net.mpls.conf.%s.input'
685 %('/'.join(ifaceobj
.name
.split("."))),
687 except Exception as e
:
688 if not setting_default_value
:
689 ifaceobj
.status
= ifaceStatus
.ERROR
690 self
.logger
.error('%s: %s' %(ifaceobj
.name
, str(e
)))
692 if (ifaceobj
.link_kind
& ifaceLinkKind
.BRIDGE
):
693 self
._set
_bridge
_forwarding
(ifaceobj
)
695 if not self
.syntax_check_sysctls(ifaceobj
):
697 ipforward
= ifaceobj
.get_attr_value_first('ip-forward')
698 ip6forward
= ifaceobj
.get_attr_value_first('ip6-forward')
699 if ifupdownflags
.flags
.PERFMODE
:
701 self
.sysctl_set('net.ipv4.conf.%s.forwarding'
702 %('/'.join(ifaceobj
.name
.split("."))),
703 utils
.boolean_support_binary(ipforward
))
705 self
.sysctl_set('net.ipv6.conf.%s.forwarding'
706 %('/'.join(ifaceobj
.name
.split("."))),
707 utils
.boolean_support_binary(ip6forward
))
709 bridge_port
= ifaceobj
.link_privflags
& ifaceLinkPrivFlags
.BRIDGE_PORT
712 self
.log_error('%s: \'ip-forward\' is not supported for '
713 'bridge port' %ifaceobj
.name
)
715 self
.log_error('%s: \'ip6-forward\' is not supported for '
716 'bridge port' %ifaceobj
.name
)
719 setting_default_value
= False
721 setting_default_value
= True
722 ipforward
= self
.ipforward
725 ipforward
= utils
.boolean_support_binary(ipforward
)
726 # File read has been used for better performance
727 # instead of using sysctl command
728 running_ipforward
= self
.read_file_oneline(
729 '/proc/sys/net/ipv4/conf/%s/forwarding'
732 if ipforward
!= running_ipforward
:
735 self
.sysctl_set('net.ipv4.conf.%s.forwarding'
736 %('/'.join(ifaceobj
.name
.split("."))),
738 except Exception as e
:
739 if not setting_default_value
:
740 ifaceobj
.status
= ifaceStatus
.ERROR
741 self
.logger
.error('%s: %s' %(ifaceobj
.name
, str(e
)))
744 setting_default_value
= False
746 setting_default_value
= True
747 ip6forward
= self
.ip6forward
750 ip6forward
= utils
.boolean_support_binary(ip6forward
)
751 # File read has been used for better performance
752 # instead of using sysctl command
753 running_ip6forward
= self
.read_file_oneline(
754 '/proc/sys/net/ipv6/conf/%s/forwarding'
756 if ip6forward
!= running_ip6forward
:
758 self
.sysctl_set('net.ipv6.conf.%s.forwarding'
759 %('/'.join(ifaceobj
.name
.split("."))),
761 except Exception as e
:
762 # There is chance of ipv6 being removed because of,
763 # for example, setting mtu < 1280
764 # In such cases, log error only if user has configured
766 if not setting_default_value
:
767 ifaceobj
.status
= ifaceStatus
.ERROR
768 self
.logger
.error('%s: %s' %(ifaceobj
.name
, str(e
)))
770 def process_mtu(self
, ifaceobj
, ifaceobj_getfunc
):
771 mtu
= ifaceobj
.get_attr_value_first('mtu')
774 default_iface_mtu
= self
.ifaces_defaults
.get(ifaceobj
.name
, {}).get('mtu')
776 if default_iface_mtu
:
778 mtu
= default_iface_mtu
779 int(default_iface_mtu
)
780 except Exception as e
:
781 self
.logger
.warning('%s: MTU value from policy file: %s' % (ifaceobj
.name
, str(e
)))
784 self
._process
_mtu
_config
(ifaceobj
, ifaceobj_getfunc
, mtu
)
786 def up_ipv6_addrgen(self
, ifaceobj
):
787 user_configured_ipv6_addrgen
= ifaceobj
.get_attr_value_first('ipv6-addrgen')
789 if not user_configured_ipv6_addrgen
and ifupdownflags
.flags
.PERFMODE
:
790 # no need to go further during perfmode (boot)
793 if not user_configured_ipv6_addrgen
and ifaceobj
.addr_method
== 'dhcp':
796 if not user_configured_ipv6_addrgen
:
797 # if user didn't configure ipv6-addrgen, should we reset to default?
798 user_configured_ipv6_addrgen
= self
.get_attr_default_value('ipv6-addrgen')
807 }.get(user_configured_ipv6_addrgen
.lower(), None)
809 if ipv6_addrgen_nl
is not None:
810 self
.ipcmd
.ipv6_addrgen(ifaceobj
.name
, ipv6_addrgen_nl
, link_created
=True)
811 # link_create=False will flush the addr cache of that intf
813 self
.logger
.warning('%s: invalid value "%s" for attribute ipv6-addrgen' % (ifaceobj
.name
, user_configured_ipv6_addrgen
))
815 def _up(self
, ifaceobj
, ifaceobj_getfunc
=None):
816 if not self
.ipcmd
.link_exists(ifaceobj
.name
):
819 if not self
.syntax_check_enable_l3_iface_forwardings(ifaceobj
, ifaceobj_getfunc
):
822 alias
= ifaceobj
.get_attr_value_first('alias')
823 current_alias
= self
.ipcmd
.link_get_alias(ifaceobj
.name
)
824 if alias
and alias
!= current_alias
:
825 self
.ipcmd
.link_set_alias(ifaceobj
.name
, alias
)
826 elif not alias
and current_alias
:
827 self
.ipcmd
.link_set_alias(ifaceobj
.name
, '')
829 self
._sysctl
_config
(ifaceobj
)
831 addr_method
= ifaceobj
.addr_method
832 force_reapply
= False
834 # release any stale dhcp addresses if present
835 if (addr_method
not in ["dhcp", "ppp"] and not ifupdownflags
.flags
.PERFMODE
and
836 not (ifaceobj
.flags
& iface
.HAS_SIBLINGS
)):
837 # if not running in perf mode and ifaceobj does not have
838 # any sibling iface objects, kill any stale dhclient
840 dhclientcmd
= dhclient()
841 if dhclientcmd
.is_running(ifaceobj
.name
):
842 # release any dhcp leases
843 dhclientcmd
.release(ifaceobj
.name
)
845 elif dhclientcmd
.is_running6(ifaceobj
.name
):
846 dhclientcmd
.release6(ifaceobj
.name
)
851 self
.ipcmd
.batch_start()
852 self
.up_ipv6_addrgen(ifaceobj
)
854 if addr_method
not in ["dhcp", "ppp"]:
855 self
._inet
_address
_config
(ifaceobj
, ifaceobj_getfunc
,
858 self
.process_mtu(ifaceobj
, ifaceobj_getfunc
)
861 self
.ipcmd
.batch_commit()
862 except Exception as e
:
863 self
.log_error('%s: %s' % (ifaceobj
.name
, str(e
)), ifaceobj
, raise_error
=False)
866 hwaddress
= self
._get
_hwaddress
(ifaceobj
)
868 running_hwaddress
= None
869 if not ifupdownflags
.flags
.PERFMODE
: # system is clean
870 running_hwaddress
= self
.ipcmd
.link_get_hwaddress(ifaceobj
.name
)
871 if hwaddress
!= running_hwaddress
:
873 netlink
.link_set_updown(ifaceobj
.name
, "down")
874 if ifaceobj
.link_kind
& ifaceLinkKind
.BOND
:
875 # if bond, down all the slaves
876 if ifaceobj
.lowerifaces
:
877 for l
in ifaceobj
.lowerifaces
:
878 netlink
.link_set_updown(l
, "down")
881 self
.ipcmd
.link_set(ifaceobj
.name
, 'address', hwaddress
)
883 netlink
.link_set_updown(ifaceobj
.name
, "up")
885 for l
in ifaceobj
.lowerifaces
:
886 netlink
.link_set_updown(l
, "up")
888 # Handle special things on a bridge
889 self
._process
_bridge
(ifaceobj
, True)
891 self
.log_error('%s: %s' %(ifaceobj
.name
, str(e
)), ifaceobj
)
893 gateways
= ifaceobj
.get_attr_value('gateway')
896 prev_gw
= self
._get
_prev
_gateway
(ifaceobj
, gateways
)
897 self
._add
_delete
_gateway
(ifaceobj
, gateways
, prev_gw
)
899 def _down(self
, ifaceobj
, ifaceobj_getfunc
=None):
901 if not self
.ipcmd
.link_exists(ifaceobj
.name
):
903 addr_method
= ifaceobj
.addr_method
904 if addr_method
not in ["dhcp", "ppp"]:
905 if ifaceobj
.get_attr_value_first('address-purge')=='no':
906 addrlist
= ifaceobj
.get_attr_value('address')
907 for addr
in addrlist
:
908 self
.ipcmd
.addr_del(ifaceobj
.name
, addr
)
909 #self.ipcmd.addr_del(ifaceobj.name, ifaceobj.get_attr_value('address')[0])
910 elif not ifaceobj
.link_kind
:
911 # for logical interfaces we don't need to remove the ip addresses
912 # kernel will do it for us on 'ip link del'
913 self
.ipcmd
.del_addr_all(ifaceobj
.name
)
914 gateways
= ifaceobj
.get_attr_value('gateway')
916 self
._delete
_gateway
(ifaceobj
, gateways
,
917 ifaceobj
.get_attr_value_first('vrf'),
918 ifaceobj
.get_attr_value_first('metric'))
919 mtu
= ifaceobj
.get_attr_value_first('mtu')
920 if (not ifaceobj
.link_kind
and mtu
and
921 self
.default_mtu
and (mtu
!= self
.default_mtu
)):
922 self
.ipcmd
.link_set(ifaceobj
.name
, 'mtu', self
.default_mtu
)
923 alias
= ifaceobj
.get_attr_value_first('alias')
925 self
.write_file('/sys/class/net/%s/ifalias' % ifaceobj
.name
, '\n')
926 # XXX hwaddress reset cannot happen because we dont know last
929 # Handle special things on a bridge
930 self
._process
_bridge
(ifaceobj
, False)
932 self
.logger
.debug('%s : %s' %(ifaceobj
.name
, str(e
)))
935 def _get_iface_addresses(self
, ifaceobj
):
936 addrlist
= ifaceobj
.get_attr_value('address')
939 if not addrlist
: return None
940 for addrindex
in range(0, len(addrlist
)):
941 addr
= addrlist
[addrindex
]
942 netmask
= ifaceobj
.get_attr_value_n('netmask', addrindex
)
944 prefixlen
= IPNetwork('%s' %addr
+
945 '/%s' %netmask
).prefixlen
946 addr
= addr
+ '/%s' %prefixlen
947 outaddrlist
.append(addr
)
950 def _get_bridge_fdbs(self
, bridgename
, vlan
):
951 fdbs
= self
._bridge
_fdb
_query
_cache
.get(bridgename
)
953 fdbs
= self
.ipcmd
.bridge_fdb_show_dev(bridgename
)
956 self
._bridge
_fdb
_query
_cache
[bridgename
] = fdbs
957 return fdbs
.get(vlan
)
959 def _check_addresses_in_bridge(self
, ifaceobj
, hwaddress
):
960 """ If the device is a bridge, make sure the addresses
961 are in the bridge """
962 if ifaceobj
.link_kind
& ifaceLinkKind
.VLAN
:
963 bridgename
= ifaceobj
.lowerifaces
[0]
964 vlan
= self
._get
_vlan
_id
(ifaceobj
)
965 if self
.ipcmd
.bridge_is_vlan_aware(bridgename
):
966 fdb_addrs
= self
._get
_bridge
_fdbs
(bridgename
, str(vlan
))
967 if not fdb_addrs
or hwaddress
not in fdb_addrs
:
971 def _query_sysctl(self
, ifaceobj
, ifaceobjcurr
):
972 bridge_port
= ifaceobj
.link_privflags
& ifaceLinkPrivFlags
.BRIDGE_PORT
973 ipforward
= ifaceobj
.get_attr_value_first('ip-forward')
976 ifaceobjcurr
.status
= ifaceStatus
.ERROR
977 ifaceobjcurr
.status_str
= ('\'ip-forward\' not supported ' +
979 ifaceobjcurr
.update_config_with_status('ip-forward', 1, None)
981 running_ipforward
= self
.read_file_oneline(
982 '/proc/sys/net/ipv4/conf/%s/forwarding'
984 running_ipforward
= utils
.get_boolean_from_string(running_ipforward
)
985 config_ipforward
= utils
.get_boolean_from_string(ipforward
)
986 ifaceobjcurr
.update_config_with_status(
988 'on' if running_ipforward
else 'off',
989 running_ipforward
!= config_ipforward
992 ip6forward
= ifaceobj
.get_attr_value_first('ip6-forward')
995 ifaceobjcurr
.status
= ifaceStatus
.ERROR
996 ifaceobjcurr
.status_str
= ('\'ip6-forward\' not supported ' +
998 ifaceobjcurr
.update_config_with_status('ip6-forward', 1, None)
1000 running_ip6forward
= self
.read_file_oneline(
1001 '/proc/sys/net/ipv6/conf/%s/forwarding'
1003 running_ip6forward
= utils
.get_boolean_from_string(running_ip6forward
)
1004 config_ip6forward
= utils
.get_boolean_from_string(ip6forward
)
1005 ifaceobjcurr
.update_config_with_status(
1007 'on' if running_ip6forward
else 'off',
1008 running_ip6forward
!= config_ip6forward
1010 mpls_enable
= ifaceobj
.get_attr_value_first('mpls-enable');
1012 running_mpls_enable
= self
.read_file_oneline(
1013 '/proc/sys/net/mpls/conf/%s/input'
1015 running_mpls_enable
= utils
.get_yesno_from_onezero(
1016 running_mpls_enable
)
1017 ifaceobjcurr
.update_config_with_status('mpls-enable',
1018 running_mpls_enable
,
1019 mpls_enable
!= running_mpls_enable
)
1022 def query_check_ipv6_addrgen(self
, ifaceobj
, ifaceobjcurr
):
1023 ipv6_addrgen
= ifaceobj
.get_attr_value_first('ipv6-addrgen')
1025 if not ipv6_addrgen
:
1028 if ipv6_addrgen
in utils
._string
_values
:
1029 ifaceobjcurr
.update_config_with_status(
1032 utils
.get_boolean_from_string(ipv6_addrgen
) == self
.ipcmd
.get_ipv6_addrgen_mode(ifaceobj
.name
)
1035 ifaceobjcurr
.update_config_with_status('ipv6-addrgen', ipv6_addrgen
, 1)
1037 def _query_check(self
, ifaceobj
, ifaceobjcurr
, ifaceobj_getfunc
=None):
1038 runningaddrsdict
= None
1039 if not self
.ipcmd
.link_exists(ifaceobj
.name
):
1040 self
.logger
.debug('iface %s not found' %ifaceobj
.name
)
1043 self
.query_check_ipv6_addrgen(ifaceobj
, ifaceobjcurr
)
1045 addr_method
= ifaceobj
.addr_method
1046 self
.query_n_update_ifaceobjcurr_attr(ifaceobj
, ifaceobjcurr
,
1047 'mtu', self
.ipcmd
.link_get_mtu
)
1048 hwaddress
= self
._get
_hwaddress
(ifaceobj
)
1050 rhwaddress
= self
.ipcmd
.link_get_hwaddress(ifaceobj
.name
)
1051 if not rhwaddress
or rhwaddress
!= hwaddress
:
1052 ifaceobjcurr
.update_config_with_status('hwaddress', rhwaddress
,
1054 elif not self
._check
_addresses
_in
_bridge
(ifaceobj
, hwaddress
):
1055 # XXX: hw address is not in bridge
1056 ifaceobjcurr
.update_config_with_status('hwaddress', rhwaddress
,
1058 ifaceobjcurr
.status_str
= 'bridge fdb error'
1060 ifaceobjcurr
.update_config_with_status('hwaddress', rhwaddress
,
1062 self
.query_n_update_ifaceobjcurr_attr(ifaceobj
, ifaceobjcurr
,
1063 'alias', self
.ipcmd
.link_get_alias
)
1064 self
._query
_sysctl
(ifaceobj
, ifaceobjcurr
)
1066 if addr_method
in ["dhcp", "ppp"]:
1068 addrs
= utils
.get_normalized_ip_addr(ifaceobj
.name
,
1069 self
._get
_iface
_addresses
(ifaceobj
))
1070 runningaddrsdict
= self
.ipcmd
.get_running_addrs(ifaceobj
)
1071 # if anycast address is configured on 'lo' and is in running config
1072 # add it to addrs so that query_check doesn't fail
1073 anycast_addr
= utils
.get_normalized_ip_addr(ifaceobj
.name
, ifaceobj
.get_attr_value_first('clagd-vxlan-anycast-ip'))
1075 anycast_addr
= anycast_addr
+'/32'
1076 if runningaddrsdict
and anycast_addr
and runningaddrsdict
.get(anycast_addr
):
1077 addrs
.append(anycast_addr
)
1079 # Set ifaceobjcurr method and family
1080 ifaceobjcurr
.addr_method
= ifaceobj
.addr_method
1081 ifaceobjcurr
.addr_family
= ifaceobj
.addr_family
1082 if not runningaddrsdict
and not addrs
:
1084 runningaddrs
= runningaddrsdict
.keys() if runningaddrsdict
else []
1085 # Add /32 netmask to configured address without netmask.
1086 # This may happen on interfaces where pointopoint is used.
1087 runningaddrs
= [ addr
if '/' in addr
else addr
+ '/32' for addr
in runningaddrs
]
1088 if runningaddrs
!= addrs
:
1089 runningaddrsset
= set(runningaddrs
) if runningaddrs
else set([])
1090 addrsset
= set(addrs
) if addrs
else set([])
1091 if (ifaceobj
.flags
& iface
.HAS_SIBLINGS
):
1094 # only check for addresses present in running config
1095 addrsdiff
= addrsset
.difference(runningaddrsset
)
1097 if addr
in addrsdiff
:
1098 ifaceobjcurr
.update_config_with_status('address',
1101 ifaceobjcurr
.update_config_with_status('address',
1104 addrsdiff
= addrsset
.symmetric_difference(runningaddrsset
)
1105 for addr
in addrsset
.union(runningaddrsset
):
1106 if addr
in addrsdiff
:
1107 ifaceobjcurr
.update_config_with_status('address',
1110 ifaceobjcurr
.update_config_with_status('address',
1113 [ifaceobjcurr
.update_config_with_status('address',
1114 addr
, 0) for addr
in addrs
]
1115 #XXXX Check broadcast address, scope, etc
1118 def query_running_ipv6_addrgen(self
, ifaceobjrunning
):
1119 ipv6_addrgen
= self
.ipcmd
.get_ipv6_addrgen_mode(ifaceobjrunning
.name
)
1122 ifaceobjrunning
.update_config('ipv6-addrgen', 'off')
1124 def _query_running(self
, ifaceobjrunning
, ifaceobj_getfunc
=None):
1125 if not self
.ipcmd
.link_exists(ifaceobjrunning
.name
):
1126 self
.logger
.debug('iface %s not found' %ifaceobjrunning
.name
)
1129 self
.query_running_ipv6_addrgen(ifaceobjrunning
)
1131 dhclientcmd
= dhclient()
1132 if (dhclientcmd
.is_running(ifaceobjrunning
.name
) or
1133 dhclientcmd
.is_running6(ifaceobjrunning
.name
)):
1134 # If dhcp is configured on the interface, we skip it
1136 isloopback
= self
.ipcmd
.link_isloopback(ifaceobjrunning
.name
)
1138 default_addrs
= ['127.0.0.1/8', '::1/128']
1139 ifaceobjrunning
.addr_family
.append('inet')
1140 ifaceobjrunning
.addr_method
= 'loopback'
1143 runningaddrsdict
= self
.ipcmd
.get_running_addrs(ifaceobjrunning
)
1144 if runningaddrsdict
:
1145 [ifaceobjrunning
.update_config('address', addr
)
1146 for addr
, addrattrs
in runningaddrsdict
.items()
1147 if addr
not in default_addrs
]
1148 mtu
= self
.ipcmd
.link_get_mtu(ifaceobjrunning
.name
)
1150 (ifaceobjrunning
.name
== 'lo' and mtu
!= '16436') or
1151 (ifaceobjrunning
.name
!= 'lo' and
1152 mtu
!= self
.get_mod_subattr('mtu', 'default'))):
1153 ifaceobjrunning
.update_config('mtu', mtu
)
1154 alias
= self
.ipcmd
.link_get_alias(ifaceobjrunning
.name
)
1156 ifaceobjrunning
.update_config('alias', alias
)
1158 ipforward
= self
.read_file_oneline(
1159 '/proc/sys/net/ipv4/conf/%s/forwarding'
1160 %ifaceobjrunning
.name
)
1163 _run_ops
= {'up' : _up
,
1165 'query-checkcurr' : _query_check
,
1166 'query-running' : _query_running
}
1169 """ returns list of ops supported by this module """
1170 return self
._run
_ops
.keys()
1172 def _init_command_handlers(self
):
1174 self
.ipcmd
= LinkUtils()
1176 def run(self
, ifaceobj
, operation
, query_ifaceobj
=None, ifaceobj_getfunc
=None):
1177 """ run address configuration on the interface object passed as argument
1180 **ifaceobj** (object): iface object
1182 **operation** (str): any of 'up', 'down', 'query-checkcurr',
1185 query_ifaceobj (object): query check ifaceobject. This is only
1186 valid when op is 'query-checkcurr'. It is an object same as
1187 ifaceobj, but contains running attribute values and its config
1188 status. The modules can use it to return queried running state
1189 of interfaces. status is success if the running state is same
1190 as user required state in ifaceobj. error otherwise.
1192 if ifaceobj
.type == ifaceType
.BRIDGE_VLAN
:
1194 op_handler
= self
._run
_ops
.get(operation
)
1197 self
._init
_command
_handlers
()
1198 if operation
== 'query-checkcurr':
1199 op_handler(self
, ifaceobj
, query_ifaceobj
,
1200 ifaceobj_getfunc
=ifaceobj_getfunc
)
1202 op_handler(self
, ifaceobj
,
1203 ifaceobj_getfunc
=ifaceobj_getfunc
)