def subnetentry(x): """ Generate a subnet declaration block given an IPv6 prefix string for inclusion in the RADVD config file. """ if x.find(":") >= 0: net = Ipv6Prefix(x) return str(net) else: return ""
def addrstr(x): if x.find(":") >= 0: net = Ipv6Prefix(x) else: net = Ipv4Prefix(x) if net.max_addr() == net.min_addr(): return "" else: if os.uname()[0] == "Linux": rtcmd = "ip route add default via" else: raise Exception("unknown platform") return "%s %s" % (rtcmd, net.min_addr())
def routestr(x): if x.find(":") >= 0: net = Ipv6Prefix(x) dst = "3ffe:4::/64" else: net = Ipv4Prefix(x) dst = "10.9.8.0/24" if net.max_addr() == net.min_addr(): return "" else: if os.uname()[0] == "Linux": rtcmd = "#/sbin/ip route add %s via" % dst else: raise Exception("unknown platform") return "%s %s" % (rtcmd, net.min_addr())
def __init__(self, ip4_prefix=None, ip6_prefix=None): """ Creates an IpPrefixes object. :param str ip4_prefix: ip4 prefix to use for generation :param str ip6_prefix: ip6 prefix to use for generation :raises ValueError: when both ip4 and ip6 prefixes have not been provided """ if not ip4_prefix and not ip6_prefix: raise ValueError("ip4 or ip6 must be provided") self.ip4 = None if ip4_prefix: self.ip4 = Ipv4Prefix(ip4_prefix) self.ip6 = None if ip6_prefix: self.ip6 = Ipv6Prefix(ip6_prefix)
def addrstr(x): if x.find(":") >= 0: net = Ipv6Prefix(x) fam = "inet6 ::" else: net = Ipv4Prefix(x) fam = "inet 0.0.0.0" if net.max_addr() == net.min_addr(): return "" else: if os.uname()[0] == "Linux": rtcmd = "ip route add default via" elif os.uname()[0] == "FreeBSD": rtcmd = "route add -%s" % fam else: raise Exception, "unknown platform" return "%s %s" % (rtcmd, net.min_addr())