Revision 1bdc9427 common.sh

b/common.sh
66 66

  
67 67
	# Enable proxy ARP
68 68
	echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
69

  
70
  # Send GARP from host to upstream router
71
  get_uplink $TABLE
72
  echo 1 > /proc/sys/net/ipv4/ip_nonlocal_bind
73
  hooks-log $0 "arping  -c3 -I $UPLINK -U $IP"
74
  arping  -c3 -I $UPLINK -U $IP
75
  echo 0 > /proc/sys/net/ipv4/ip_nonlocal_bind
76

  
69 77
}
70 78

  
71 79
function routed_setup_ipv6 {
72 80
	# Add a routing entry for the eui-64
73
	prefix=$NETWORK_SUBNET6
74
	uplink=$(ip -6 route list table $TABLE | grep "default via" | awk '{print $5}')
75
	eui64=$($MAC2EUI64 $MAC $prefix)
81
  get_uplink $TABLE "-6"
82
  get_eui64 $MAC $NETWORK_SUBNET6
76 83

  
77
  if [ -z "$eui64" -o -z "$TABLE" -o -z "$INTERFACE" -o -z "$uplink" ]
84
  if [ -z "$EUI64" -o -z "$TABLE" -o -z "$INTERFACE" -o -z "$UPLINK" ]
78 85
  then
79 86
    return
80 87
  fi
81 88

  
82 89
	ip -6 rule add dev $INTERFACE table $TABLE
83
	ip -6 ro replace $eui64/128 dev $INTERFACE table $TABLE
84
	ip -6 neigh add proxy $eui64 dev $uplink
90
	ip -6 ro replace $EUI64/128 dev $INTERFACE table $TABLE
91
	ip -6 neigh add proxy $EUI64 dev $UPLINK
85 92

  
86 93
	# disable proxy NDP since we're handling this on userspace
87 94
	# this should be the default, but better safe than sorry
88 95
	echo 0 > /proc/sys/net/ipv6/conf/$INTERFACE/proxy_ndp
96

  
97
  # Send Unsolicited Neighbor Advertisement
98
  hooks-log $0 "ndsend $EUI64 $UPLINK"
99
  ndsend $EUI64 $UPLINK
100

  
89 101
}
90 102

  
91 103
# pick a firewall profile per NIC, based on tags (and apply it)
......
171 183

  
172 184
}
173 185

  
186
function get_uplink {
187

  
188
  local table=$1
189
  local version=$2
190
  UPLINK=$(ip "$version" route list table "$table" | grep "default via" | awk '{print $5}')
191

  
192
}
193

  
194
# Because we do not have IPv6 value in our environment
195
# we caclulate it based on the NIC's MAC and the IPv6 subnet (if any)
196
# first argument MAC second IPv6 subnet
197
# Changes global value EUI64
198
get_eui64 () {
199

  
200
  local mac=$1
201
  local prefix=$2
202

  
203
  if [ -z "$prefix" ]; then
204
    EUI64=
205
  else
206
    EUI64=$($MAC2EUI64 $mac $prefix)
207
  fi
208

  
209
}

Also available in: Unified diff