Statistics
| Branch: | Tag: | Revision:

root / snf-network-ipless-routing-on @ 8306820f

History | View | Annotate | Download (1.3 kB)

1
#!/bin/bash
2

    
3
source /etc/default/snf-network
4

    
5
source $CONF
6

    
7
if [ ! -e $STATE_DIR/infra ]; then 
8
  echo No infra file found!
9
  echo run: snf-network-build-node-infra
10
  exit 1
11
fi
12

    
13
source $STATE_DIR/infra
14

    
15
if [ $# -ne 5 ]; then
16
  echo "Usage: $0 <routing table> <subnet> <gateway> <subnet6> <gateway6>"
17
  exit 1
18
fi
19

    
20
RT_TABLES=/etc/iproute2/rt_tables
21

    
22
TABLE=$1
23
SUBNET=$2
24
GATEWAY=$3
25
SUBNET6=$4
26
GATEWAY6=$5
27

    
28
VLAN=$PUBLIC_VLAN
29
ARP_IP=$(ipcalc $SUBNET | grep HostMax | awk '{print $2}')
30

    
31
ip link set $VLAN up
32

    
33
ID=$(wc -l < $RT_TABLES)
34
echo $((ID+1)) $TABLE >> $RT_TABLES
35

    
36
if [ -n "$SUBNET" ]; then
37
  ip rule add iif $VLAN table $TABLE
38
  ip route add $SUBNET dev $VLAN table main 
39
  ip route add $SUBNET dev $VLAN table $TABLE
40
  if [ -n "$GATEWAY" ]; then
41
    ip route add default via $GATEWAY dev $VLAN table $TABLE
42
  fi
43
  arptables -A OUTPUT -o $VLAN --opcode request -j mangle --mangle-ip-s $ARP_IP 
44
  echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
45
  echo 1 > /proc/sys/net/ipv4/conf/$VLAN/proxy_arp
46
fi
47

    
48
if [ -n "$SUBNET6" ]; then
49
  ip -6 rule add iif $VLAN table $TABLE
50
  ip -6 route add $SUBNET6 dev $VLAN table main
51
  ip -6 route add $SUBNET6 dev $VLAN table $TABLE
52
  if [ -n "$GATEWAY6" ]; then
53
    ip -6 route add default via $GATEWAY6 dev $VLAN table $TABLE
54
  fi
55
  echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
56
  echo 1 > /proc/sys/net/ipv6/conf/$VLAN/proxy_ndp
57
fi