コード例 #1
0
def _set_dmzlan_ifup_address_and_route(data, pos):
	ret = True
	emsg = []

	# Always ifups dmz
	e = xt_func.sudo(["ip link set dev", pos, "up"])
	if not e[0]: 
		ret = False
		emsg.append(e[1])

	for i in data["basic-subnet"]:
		ip_range = xt_func.iprange2list(i["ip"])
		inet = xt_func.block2cidr(ip_range[0]+ "/"+ i["mask"]) 
		for ip in ip_range:
			e = xt_func.sudo(["ip addr add", ip+ "/"+ i["mask"], "brd + dev", pos])
			if not e[0]: 
				ret = False
				emsg.append(e[1])
		e = xt_func.sudo(["ip route add", inet, "dev", pos, "src", ip_range[0], "table", const.RTAB[pos]])

	for i in data["static-route"]:
		e = xt_func.sudo(["ip route add", i["subnet"], "via", i["gateway"], "dev", pos, "table", const.RTAB[pos]])
		if not e[0]: 
			ret = False
			emsg.append(e[1])

	return (ret, emsg)
コード例 #2
0
def _set_static_wan_ifup_address_and_route(data, pos):
	ret = True
	emsg = []

	if data["enable"] != 1: return (ret, [pos, "disabled"])

	e = xt_func.sudo(["ip link set dev", pos, "up"])
	if not e[0]: 
		ret = False
		emsg.append(e[1])

	# static supports only one subnet
	fst_ip = data["static-mode"]["ip"][0].split("-")[0]
	inet = xt_func.block2cidr(fst_ip + "/" + data["static-mode"]["mask"]) 
	for i in data["static-mode"]["ip"]:
		ip_range = xt_func.iprange2list(i)
		for ip in ip_range:
			e = xt_func.sudo(["ip addr add", ip+ "/"+ data["static-mode"]["mask"], "brd + dev", pos])
			if not e[0]: 
				ret = False
				emsg.append(e[1])
	e = xt_func.sudo(["ip route add default via", data["static-mode"]["gateway"], "dev", pos, "table", const.RTAB[pos]])
	e = xt_func.sudo(["ip route append default via", data["static-mode"]["gateway"], "dev", pos])

	if len(data["public-ip-passthrough"]["ip"]) > 0:
		#Copy addresses to DMZ for public-ip-passthrough
		for ip in ip_range:
			e = xt_func.sudo(["ip addr add", ip+ "/"+ data["static-mode"]["mask"], "brd + dev dmz"])
			if not e[0]: 
				ret = False
				emsg.append(e[1])
		#Don't forget route tables 
		e = xt_func.sudo(["ip route del", inet, "dev dmz"])
		e = xt_func.sudo(["ip route add", inet, "src", fst_ip, "dev dmz table", const.RTAB["dmz"]])

	return (ret, emsg)