def _intf_ipv4_gateway(self, ifname): """ Return the default gateway if it belongs to the interface """ defgw = self.route.get(self.default_dst_ipv4) xaddr = dumbnet.intf.get(self, ifname)["addr"] route = self.route.get(xaddr) if not defgw or (route and defgw != route): return None defgwstr = str(defgw) address = network.parse_ipv4(dumbnet.ip_ntoa(xaddr.ip)) netmask = network.bitmask_to_mask_ipv4(xaddr.bits) if network.ipv4_in_network(network.parse_ipv4(defgwstr), netmask, network.mask_ipv4(netmask, address)): return defgwstr
def get_netiface_info(self, iface): try: info = self.netcfg.get(iface) except OSError: return False if not info or not info.has_key('family'): return False info['carrier'] = False info['physicalif'] = False info['vlanif'] = False info['vlan-id'] = None info['vlan-raw-device'] = None info['aliasif'] = False info['alias-raw-device'] = None info['hwtypeid'] = None info['options'] = None if network.is_linux_netdev_if(iface): info['carrier'] = network.is_interface_plugged(iface) info['flags'] = network.get_interface_flags(iface) info['physicalif'] = network.is_linux_phy_if(iface) info['dummyif'] = network.is_linux_dummy_if(iface) info['vlanif'] = network.is_linux_vlan_if(iface) info['hwtypeid'] = network.get_interface_hwtypeid(iface) if not info['physicalif'] and info.has_key('gateway'): del info['gateway'] if not info.has_key('hwaddress'): info['hwaddress'] = network.get_interface_hwaddress(iface) if not info.has_key('mtu'): info['mtu'] = network.get_interface_mtu(iface) else: if network.is_alias_if(iface): info['aliasif'] = True phyifname = network.phy_name_from_alias_if(iface) info['alias-raw-device'] = phyifname if network.is_linux_netdev_if(phyifname): if info.has_key('gateway'): try: phyinfo = self.netcfg.get(phyifname) if phyinfo.get('gateway') == info['gateway']: del info['gateway'] except OSError: pass info['carrier'] = network.is_interface_plugged(phyifname) info['hwtypeid'] = network.get_interface_hwtypeid(phyifname) if not info.has_key('flags'): info['flags'] = None if not info.has_key('hwaddress'): info['hwaddress'] = None if not info.has_key('mtu'): info['mtu'] = None if info['family'] in ('inet', 'inet6'): inetxparsed = self.inetxparser.get(iface) if inetxparsed: info['options'] = xivo_config.unreserved_interfaces_options(inetxparsed) xdict = dict(inetxparsed) info['method'] = xdict.get('method') info['vlan-id'] = xdict.get('vlan-id') info['vlan-raw-device'] = xdict.get('vlan-raw-device') if 'address' not in info \ and 'address' in xdict \ and 'netmask' in xdict: info['address'] = xdict.get('address') info['netmask'] = xdict['netmask'] if 'broadcast' in xdict: info['broadcast'] = xdict['broadcast'] if 'network' in xdict: info['network'] = xdict['network'] if info['family'] == 'inet' \ and not info.has_key('gateway') \ and info.has_key('netmask') \ and info.has_key('network') \ and xdict.has_key('gateway') \ and network.ipv4_in_network(network.parse_ipv4(xdict['gateway']), network.parse_ipv4(info['netmask']), network.parse_ipv4(info['network'])): info['gateway'] = xdict['gateway'] else: info['method'] = None if info['vlanif']: vconfig = network.get_vlan_info(iface) info['vlan-id'] = vconfig.get('vlan-id', info['vlan-id']) info['vlan-raw-device'] = vconfig.get('vlan-raw-device', info['vlan-raw-device']) return info
def get_netiface_info(self, iface): try: info = self.netcfg.get(iface) except OSError: return False if not info or not info.has_key("family"): return False info["carrier"] = False info["physicalif"] = False info["vlanif"] = False info["vlan-id"] = None info["vlan-raw-device"] = None info["aliasif"] = False info["alias-raw-device"] = None info["hwtypeid"] = None info["options"] = None if network.is_linux_netdev_if(iface): info["carrier"] = network.is_interface_plugged(iface) info["flags"] = network.get_interface_flags(iface) info["physicalif"] = network.is_linux_phy_if(iface) info["dummyif"] = network.is_linux_dummy_if(iface) info["vlanif"] = network.is_linux_vlan_if(iface) info["hwtypeid"] = network.get_interface_hwtypeid(iface) if not info["physicalif"] and info.has_key("gateway"): del info["gateway"] if not info.has_key("hwaddress"): info["hwaddress"] = network.get_interface_hwaddress(iface) if not info.has_key("mtu"): info["mtu"] = network.get_interface_mtu(iface) else: if network.is_alias_if(iface): info["aliasif"] = True phyifname = network.phy_name_from_alias_if(iface) info["alias-raw-device"] = phyifname if network.is_linux_netdev_if(phyifname): if info.has_key("gateway"): try: phyinfo = self.netcfg.get(phyifname) if phyinfo.get("gateway") == info["gateway"]: del info["gateway"] except OSError: pass info["carrier"] = network.is_interface_plugged(phyifname) info["hwtypeid"] = network.get_interface_hwtypeid(phyifname) if not info.has_key("flags"): info["flags"] = None if not info.has_key("hwaddress"): info["hwaddress"] = None if not info.has_key("mtu"): info["mtu"] = None if info["family"] in ("inet", "inet6"): inetxparsed = self.inetxparser.get(iface) if inetxparsed: info["options"] = xivo_config.unreserved_interfaces_options(inetxparsed) xdict = dict(inetxparsed) info["method"] = xdict.get("method") info["vlan-id"] = xdict.get("vlan-id") info["vlan-raw-device"] = xdict.get("vlan-raw-device") if "address" not in info and "address" in xdict and "netmask" in xdict: info["address"] = xdict.get("address") info["netmask"] = xdict["netmask"] if "broadcast" in xdict: info["broadcast"] = xdict["broadcast"] if "network" in xdict: info["network"] = xdict["network"] if ( info["family"] == "inet" and not info.has_key("gateway") and info.has_key("netmask") and info.has_key("network") and xdict.has_key("gateway") and network.ipv4_in_network( network.parse_ipv4(xdict["gateway"]), network.parse_ipv4(info["netmask"]), network.parse_ipv4(info["network"]), ) ): info["gateway"] = xdict["gateway"] else: info["method"] = None if info["vlanif"]: vconfig = network.get_vlan_info(iface) info["vlan-id"] = vconfig.get("vlan-id", info["vlan-id"]) info["vlan-raw-device"] = vconfig.get("vlan-raw-device", info["vlan-raw-device"]) return info