Skip to content

Commit 849059d

Browse files
committed
Wrapping up some work
1 parent 4498b8a commit 849059d

8 files changed

Lines changed: 440 additions & 39 deletions

create-fw-mark-rule.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ if [ "$RES" -eq "0" ]; then
1010
fi
1111

1212
ip rule add fwmark ${MARK} table ${TABLE}
13+
ip rule show fwmark ${MARK}

gen_lan_interfaces.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env ruby
2+
3+
$rt_tables = {}
4+
$rt_marks = {}
5+
$lan = true
6+
7+
8+
def gen_rt_table(interface)
9+
return 0 if $lan
10+
while true do
11+
table = rand(1000..2000).to_s
12+
if $rt_tables[table] == nil
13+
$rt_tables[table] = interface
14+
return table
15+
else
16+
next
17+
end
18+
end
19+
end
20+
21+
def gen_rt_mark(interface)
22+
return 0 if $lan
23+
while true do
24+
mark = rand(1000..2000).to_s
25+
if $rt_marks[mark] == nil
26+
$rt_marks[mark] = interface
27+
return mark
28+
else
29+
next
30+
end
31+
end
32+
end
33+
34+
35+
wan_interfaces = {}
36+
37+
("23".."23").each do |i|
38+
wan_interfaces["ether#{i.gsub(/^0/, "")}"] = { "rt_table" => gen_rt_table("ether#{i.gsub(/^0/, "")}"), "gw" => "192.168.2#{i}.254" , "rt_mark" => gen_rt_mark("ether#{i.gsub(/^0/, "")}") }
39+
end
40+
41+
wan_interfaces.each_key do |interface|
42+
puts("#{interface} #{wan_interfaces[interface]["gw"]} #{wan_interfaces[interface]["rt_table"]} #{wan_interfaces[interface]["rt_mark"]} ")
43+
end

gen_wan_interfaces.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env ruby
2+
3+
$rt_tables = {}
4+
$rt_marks = {}
5+
6+
def gen_rt_table(interface)
7+
while true do
8+
table = rand(1000..2000).to_s
9+
if $rt_tables[table] == nil
10+
$rt_tables[table] = interface
11+
return table
12+
else
13+
next
14+
end
15+
end
16+
end
17+
18+
def gen_rt_mark(interface)
19+
while true do
20+
mark = rand(1000..2000).to_s
21+
if $rt_marks[mark] == nil
22+
$rt_marks[mark] = interface
23+
return mark
24+
else
25+
next
26+
end
27+
end
28+
end
29+
30+
31+
wan_interfaces = {}
32+
33+
("05".."15").each do |i|
34+
wan_interfaces["ether#{i.gsub(/^0/, "")}"] = { "rt_table" => gen_rt_table("ether#{i.gsub(/^0/, "")}"), "gw" => "192.168.2#{i}.254" , "rt_mark" => gen_rt_mark("ether#{i.gsub(/^0/, "")}") }
35+
end
36+
37+
38+
wan_interfaces.each_key do |interface|
39+
puts("#{interface} #{wan_interfaces[interface]["gw"]} #{wan_interfaces[interface]["rt_table"]} #{wan_interfaces[interface]["rt_mark"]} ")
40+
end

lan_interfaces.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ether23 192.168.223.254 0 0

new-next-hop-table.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
NEXT_HOP_TABLE_NUMBER="$1"
44
GW="$2"
5+
MARK="$3"
56

67
DTABLE="${NEXT_HOP_TABLE_NUMBER}"
78

@@ -16,3 +17,9 @@ ip route show | grep -Ev '^default' \
1617
done
1718

1819
ip route add default via ${GW} table ${DTABLE}
20+
21+
DTABLE_SIZE=$(ip route show table ${DTABLE})
22+
## Size is > 0
23+
24+
DTABLE_ROUTE_TEST=$(ip route get 8.8.8.8 mark 0x${MARK})
25+
# Includes GW

0 commit comments

Comments
 (0)