def apply_settings(self): if self != NetConf.get_default(): NetConf.get_default().remove_settings() NetConf.default_inst = self try: create_bridge("pan1") except BridgeException as e: if e.errno != errno.EEXIST: raise if self.ip4_changed or not self.locked("netconfig"): self.enable_ip4_forwarding() if have("ip"): ret = call(["ip", "link", "set", "dev", "pan1", "up"]) if ret != 0: raise NetworkSetupError( "Failed to bring up interface pan1") ret = call([ "ip", "address", "add", "/".join( (self.ip4_address, self.ip4_mask)), "dev", "pan1" ]) if ret != 0: raise NetworkSetupError( "Failed to add ip address %s with netmask %s" % (self.ip4_address, self.ip4_mask)) elif have('ifconfig'): ret = call([ "ifconfig", "pan1", self.ip4_address, "netmask", self.ip4_mask, "up" ]) if ret != 0: raise NetworkSetupError( "Failed to add ip address %s with netmask %s" % (self.ip4_address, self.ip4_mask)) else: raise NetworkSetupError( "Neither ifconfig or ip commands are found. Please install net-tools or iproute2" ) self.lock("netconfig") if self.ip4_changed or not self.locked("iptables"): self.del_ipt_rules() self.add_ipt_rule( "nat", "POSTROUTING", "-s %s/%s -j MASQUERADE" % (self.ip4_address, self.ip4_mask)) self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT") self.add_ipt_rule("filter", "FORWARD", "-o pan1 -j ACCEPT") self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT") self.lock("iptables") if self.dhcp_handler: self.dhcp_handler.do_apply() self.ip4_changed = False self.store()
def apply_settings(self): if self.ip4_address is None or self.ip4_mask is None: if self.ip4_changed: self.ip4_changed = False self.store() return if self != NetConf.get_default(): NetConf.get_default().remove_settings() NetConf.default_inst = self try: create_bridge("pan1") except BridgeException as e: if e.errno != errno.EEXIST: raise ip_str = inet_ntoa(self.ip4_address) mask_str = inet_ntoa(self.ip4_mask) if self.ip4_changed or not self.locked("netconfig"): self.enable_ip4_forwarding() if have("ip"): ret = call(["ip", "link", "set", "pan1", "up"]) if ret != 0: raise NetworkSetupError("Failed to bring up interface pan1") ret = call(["ip", "address", "add", "/".join((ip_str, mask_str)), "dev", "pan1"]) if ret != 0: raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (ip_str, mask_str)) else: ret = call(["ifconfig", "pan1", ip_str, "netmask", mask_str, "up"]) if ret != 0: raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (ip_str, mask_str)) self.lock("netconfig") if self.ip4_changed or not self.locked("iptables"): self.del_ipt_rules() self.add_ipt_rule("nat", "POSTROUTING", "-s %s/%s -j MASQUERADE" % (ip_str, mask_str)) self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT") self.add_ipt_rule("filter", "FORWARD", "-o pan1 -j ACCEPT") self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT") self.lock("iptables") if self.dhcp_handler: self.dhcp_handler.do_apply() self.ip4_changed = False self.store()
def apply_settings(self): if self.ip4_address is None or self.ip4_mask is None: if self.ip4_changed: self.ip4_changed = False self.store() return if self != NetConf.get_default(): NetConf.get_default().remove_settings() NetConf.default_inst = self try: create_bridge("pan1") except BridgeException as e: if e.errno != errno.EEXIST: raise ip_str = inet_ntoa(self.ip4_address) mask_str = inet_ntoa(self.ip4_mask) if self.ip4_changed or not self.locked("netconfig"): self.enable_ip4_forwarding() if have("ip"): ret = call(["ip", "link", "set", "dev", "pan1", "up"]) if ret != 0: raise NetworkSetupError("Failed to bring up interface pan1") ret = call(["ip", "address", "add", "/".join((ip_str, mask_str)), "dev", "pan1"]) if ret != 0: raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (ip_str, mask_str)) else: ret = call(["ifconfig", "pan1", ip_str, "netmask", mask_str, "up"]) if ret != 0: raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (ip_str, mask_str)) self.lock("netconfig") if self.ip4_changed or not self.locked("iptables"): self.del_ipt_rules() self.add_ipt_rule("nat", "POSTROUTING", "-s %s/%s -j MASQUERADE" % (ip_str, mask_str)) self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT") self.add_ipt_rule("filter", "FORWARD", "-o pan1 -j ACCEPT") self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT") self.lock("iptables") if self.dhcp_handler: self.dhcp_handler.do_apply() self.ip4_changed = False self.store()
def apply_settings(self): if self != NetConf.get_default(): NetConf.get_default().remove_settings() NetConf.default_inst = self try: create_bridge("pan1") except BridgeException as e: if e.errno != errno.EEXIST: raise if self.ip4_changed or not self.locked("netconfig"): self.enable_ip4_forwarding() if have("ip"): ret = call(["ip", "link", "set", "dev", "pan1", "up"]) if ret != 0: raise NetworkSetupError("Failed to bring up interface pan1") ret = call(["ip", "address", "add", "/".join((self.ip4_address, self.ip4_mask)), "dev", "pan1"]) if ret != 0: raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (self.ip4_address, self.ip4_mask)) elif have('ifconfig'): ret = call(["ifconfig", "pan1", self.ip4_address, "netmask", self.ip4_mask, "up"]) if ret != 0: raise NetworkSetupError("Failed to add ip address %s with netmask %s" % (self.ip4_address, self.ip4_mask)) else: raise NetworkSetupError( "Neither ifconfig or ip commands are found. Please install net-tools or iproute2") self.lock("netconfig") if self.ip4_changed or not self.locked("iptables"): self.del_ipt_rules() self.add_ipt_rule("nat", "POSTROUTING", "-s %s/%s -j MASQUERADE" % (self.ip4_address, self.ip4_mask)) self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT") self.add_ipt_rule("filter", "FORWARD", "-o pan1 -j ACCEPT") self.add_ipt_rule("filter", "FORWARD", "-i pan1 -j ACCEPT") self.lock("iptables") if self.dhcp_handler: self.dhcp_handler.do_apply() self.ip4_changed = False self.store()