platinasystems / go

Other
9 stars 68 forks source link

vnet ignores routes where the next-hop is within the route prefix #118

Open stigt opened 6 years ago

stigt commented 6 years ago

Add a static route for 10.0.0.0/8 with next-hop 10.15.0.4 (which is within the /8):

stig@invader1:~$ sudo goes vnet show ip fib
 Table                   Destination                               Adjacency
     default                  10.15.0.0/24       3: glean eth-0-0
     default                  10.15.0.1/32       4: local eth-0-0

stig@invader1:~$ sudo ip route add 10.0.0.0/8 via 10.15.0.4 The route is ignored by vnet:

stig@invader1:~$ sudo goes vnet show ip fib
 Table                   Destination                               Adjacency
     default                  10.15.0.0/24       3: glean eth-0-0
     default                  10.15.0.1/32       4: local eth-0-0

However the linux kernel does accept it.

stig@invader1:~$ ip ro
default via 192.168.101.2 dev eth0 
10.0.0.0/8 via 10.15.0.4 dev eth-0-0                                              <========
10.15.0.0/24 dev eth-0-0 proto kernel scope link src 10.15.0.1 
192.168.101.0/24 dev eth0 proto kernel scope link src 192.168.101.121 

Vnet does print the netlink message to syslog:

Apr  3 18:07:24 invader1 goes.vnetd[14040]: 18:07:24.693538 default: netlink prefix 10.0.0.0/8 matches next-hop 10.15.0.4: RTM_NEWROUTE:
Apr  3 18:07:24 invader1 goes.vnetd[14040]: len: 60
Apr  3 18:07:24 invader1 goes.vnetd[14040]: seq: 1522804045
Apr  3 18:07:24 invader1 goes.vnetd[14040]: pid: 14629
Apr  3 18:07:24 invader1 goes.vnetd[14040]: flags: match|exclude, atomic|create
Apr  3 18:07:24 invader1 goes.vnetd[14040]: family: INET
Apr  3 18:07:24 invader1 goes.vnetd[14040]: srclen: 0
Apr  3 18:07:24 invader1 goes.vnetd[14040]: dstlen: 8
Apr  3 18:07:24 invader1 goes.vnetd[14040]: tos: 0
Apr  3 18:07:24 invader1 goes.vnetd[14040]: table: MAIN
Apr  3 18:07:24 invader1 goes.vnetd[14040]: protocol: BOOT
Apr  3 18:07:24 invader1 goes.vnetd[14040]: scope: Universe
Apr  3 18:07:24 invader1 goes.vnetd[14040]: type: UNICAST
Apr  3 18:07:24 invader1 goes.vnetd[14040]: DST: 10.0.0.0
Apr  3 18:07:24 invader1 goes.vnetd[14040]: OIF: 281
Apr  3 18:07:24 invader1 goes.vnetd[14040]: GATEWAY: 10.15.0.4
Apr  3 18:07:24 invader1 goes.vnetd[14040]: TABLE: 254

If I comment out the nha.MatchesPrefix in fib.go, then vnet does the right thing. However there are 6 calls to MatchesPrefix that need to be checked if they are needed.

diff --git a/vnet/ip4/fib.go b/vnet/ip4/fib.go
index 981810b..17e85ee 100644
--- a/vnet/ip4/fib.go
+++ b/vnet/ip4/fib.go
@@ -678,7 +678,7 @@ func (f *Fib) addDelRouteNextHop(m *Main, p *Prefix, nha Address, nhr NextHopper
        ok                    bool
    )

-   if !isDel && nha.MatchesPrefix(p) && p.Address != AddressUint32(0) {
+   if false && !isDel && nha.MatchesPrefix(p) && p.Address != AddressUint32(0) {
        err = fmt.Errorf("prefix %s matches next-hop %s", p, &nha)
        return
    }
jignesh045 commented 6 years ago

Issue verification status: Open (still exists)

Issue verified in the following build:

root@invader45:~# goes version
github.com/platinasystems/go: v0.41-244-g49d9e6da
github.com/platinasystems/fe1: v0.2-520-g85494c1
github.com/platinasystems/firmware-fe1a: v0.2
root@invader45:~#

root@invader45:~# dpkg --list | grep kernel
ii  kmod                           18-3                             amd64        tools for managing Linux kernel modules
ii  libdrm2:amd64                  2.4.58-2                         amd64        Userspace interface to kernel DRM services -- runtime
ii  linux-image-4.13.0-platina-mk1 4.13-117-g00814e4e1a1e           amd64        Linux kernel, version 4.13.0-platina-mk1
ii  rsyslog                        8.4.2-1+deb8u2                   amd64        reliable system and kernel logging daemon
root@invader45:~#

Steps executed:

root@invader45:/# ifconfig eth-11-1 10.15.0.1/24
root@invader45:/#

root@invader45:/# sudo goes vnet show ip fib | grep eth-11-1
     default                  10.15.0.0/24      23: glean eth-11-1
     default                  10.15.0.1/32      24: local eth-11-1
root@invader45:/#

root@invader45:/# sudo ip route add 10.0.0.0/8 via 10.15.0.4
root@invader45:/#

root@invader45:/# sudo goes vnet show ip fib
 Table                   Destination                               Adjacency
     default                   10.0.1.0/24       3: glean eth-1-1
     default                  10.0.1.45/32       4: local eth-1-1
     default                   10.0.2.0/24       5: glean eth-2-1
     default                  10.0.2.45/32       6: local eth-2-1
     default                   10.0.3.0/24       7: glean eth-3-1
     default                  10.0.3.45/32       8: local eth-3-1
     default                   10.0.4.0/24       9: glean eth-4-1
     default                  10.0.4.45/32      10: local eth-4-1
     default                   10.0.5.0/24      11: glean eth-5-1
     default                  10.0.5.45/32      12: local eth-5-1
     default                   10.0.6.0/24      13: glean eth-6-1
     default                  10.0.6.45/32      14: local eth-6-1
     default                   10.0.7.0/24      15: glean eth-7-1
     default                  10.0.7.45/32      16: local eth-7-1
     default                   10.0.8.0/24      17: glean eth-8-1
     default                  10.0.8.45/32      18: local eth-8-1
     default                   10.0.9.0/24      19: glean eth-9-1
     default                  10.0.9.45/32      20: local eth-9-1
     default                  10.0.10.0/24      21: glean eth-10-1
     default                 10.0.10.45/32      22: local eth-10-1
     default                  10.0.12.0/24      25: glean eth-12-1
     default                 10.0.12.45/32      26: local eth-12-1
     default                  10.0.13.0/24      27: glean eth-13-1
     default                 10.0.13.45/32      28: local eth-13-1
     default                  10.0.14.0/24      29: glean eth-14-1
     default                 10.0.14.45/32      30: local eth-14-1
     default                  10.0.15.0/24      31: glean eth-15-1
     default                 10.0.15.45/32      32: local eth-15-1
     default                  10.0.16.0/24      33: glean eth-16-1
     default                 10.0.16.45/32      34: local eth-16-1
     default                  10.0.17.0/24      35: glean eth-17-1
     default                 10.0.17.45/32      36: local eth-17-1
     default                  10.0.18.0/24      37: glean eth-18-1
     default                 10.0.18.45/32      38: local eth-18-1
     default                  10.0.19.0/24      39: glean eth-19-1
     default                 10.0.19.45/32      40: local eth-19-1
     default                  10.0.20.0/24      41: glean eth-20-1
     default                 10.0.20.45/32      42: local eth-20-1
     default                  10.0.21.0/24      43: glean eth-21-1
     default                 10.0.21.45/32      44: local eth-21-1
     default                  10.0.22.0/24      45: glean eth-22-1
     default                 10.0.22.45/32      46: local eth-22-1
     default                  10.0.23.0/24      47: glean eth-23-1
     default                 10.0.23.45/32      48: local eth-23-1
     default                  10.0.24.0/24      49: glean eth-24-1
     default                 10.0.24.45/32      50: local eth-24-1
     default                  10.0.25.0/24      51: glean eth-25-1
     default                 10.0.25.45/32      52: local eth-25-1
     default                  10.0.26.0/24      53: glean eth-26-1
     default                 10.0.26.45/32      54: local eth-26-1
     default                  10.0.27.0/24      55: glean eth-27-1
     default                 10.0.27.45/32      56: local eth-27-1
     default                  10.0.28.0/24      57: glean eth-28-1
     default                 10.0.28.45/32      58: local eth-28-1
     default                  10.0.29.0/24      59: glean eth-29-1
     default                 10.0.29.45/32      60: local eth-29-1
     default                  10.0.30.0/24      61: glean eth-30-1
     default                 10.0.30.45/32      62: local eth-30-1
     default                  10.0.31.0/24      63: glean eth-31-1
     default                 10.0.31.45/32      64: local eth-31-1
     default                  10.0.32.0/24      65: glean eth-32-1
     default                 10.0.32.45/32      66: local eth-32-1
     default                  10.15.0.0/24      23: glean eth-11-1
     default                  10.15.0.1/32      24: local eth-11-1
root@invader45:/# ip route
default via 172.17.2.1 dev eth0
10.0.0.0/8 via 10.15.0.4 dev eth-11-1
10.0.1.0/24 dev eth-1-1 proto kernel scope link src 10.0.1.45
10.0.2.0/24 dev eth-2-1 proto kernel scope link src 10.0.2.45
10.0.3.0/24 dev eth-3-1 proto kernel scope link src 10.0.3.45
10.0.4.0/24 dev eth-4-1 proto kernel scope link src 10.0.4.45 linkdown
10.0.5.0/24 dev eth-5-1 proto kernel scope link src 10.0.5.45
10.0.6.0/24 dev eth-6-1 proto kernel scope link src 10.0.6.45
10.0.7.0/24 dev eth-7-1 proto kernel scope link src 10.0.7.45
10.0.8.0/24 dev eth-8-1 proto kernel scope link src 10.0.8.45 linkdown
10.0.9.0/24 dev eth-9-1 proto kernel scope link src 10.0.9.45
10.0.10.0/24 dev eth-10-1 proto kernel scope link src 10.0.10.45
10.0.12.0/24 dev eth-12-1 proto kernel scope link src 10.0.12.45 linkdown
10.0.13.0/24 dev eth-13-1 proto kernel scope link src 10.0.13.45 linkdown
10.0.14.0/24 dev eth-14-1 proto kernel scope link src 10.0.14.45
10.0.15.0/24 dev eth-15-1 proto kernel scope link src 10.0.15.45
10.0.16.0/24 dev eth-16-1 proto kernel scope link src 10.0.16.45 linkdown
10.0.17.0/24 dev eth-17-1 proto kernel scope link src 10.0.17.45
10.0.18.0/24 dev eth-18-1 proto kernel scope link src 10.0.18.45 linkdown
10.0.19.0/24 dev eth-19-1 proto kernel scope link src 10.0.19.45
10.0.20.0/24 dev eth-20-1 proto kernel scope link src 10.0.20.45 linkdown
10.0.21.0/24 dev eth-21-1 proto kernel scope link src 10.0.21.45
10.0.22.0/24 dev eth-22-1 proto kernel scope link src 10.0.22.45 linkdown
10.0.23.0/24 dev eth-23-1 proto kernel scope link src 10.0.23.45
10.0.24.0/24 dev eth-24-1 proto kernel scope link src 10.0.24.45 linkdown
10.0.25.0/24 dev eth-25-1 proto kernel scope link src 10.0.25.45
10.0.26.0/24 dev eth-26-1 proto kernel scope link src 10.0.26.45 linkdown
10.0.27.0/24 dev eth-27-1 proto kernel scope link src 10.0.27.45
10.0.28.0/24 dev eth-28-1 proto kernel scope link src 10.0.28.45 linkdown
10.0.29.0/24 dev eth-29-1 proto kernel scope link src 10.0.29.45
10.0.30.0/24 dev eth-30-1 proto kernel scope link src 10.0.30.45 linkdown
10.0.31.0/24 dev eth-31-1 proto kernel scope link src 10.0.31.45
10.0.32.0/24 dev eth-32-1 proto kernel scope link src 10.0.32.45 linkdown
10.15.0.0/24 dev eth-11-1 proto kernel scope link src 10.15.0.1
172.17.2.0/23 dev eth0 proto kernel scope link src 172.17.2.45
172.18.0.0/16 dev docker0 proto kernel scope link src 172.18.0.1 linkdown
root@invader45:/#

root@invader45:/# sudo goes vnet show ip fib | grep 10.15.0.4
root@invader45:/#

Syslog:

Jul 19 03:55:28 debian goes.vnetd[8743]: 03:55:28.559851 default: netlink prefix 10.0.0.0/8 matches next-hop 10.15.0.4: RTM_NEWROUTE:
Jul 19 03:55:28 debian goes.vnetd[8743]: len: 60
Jul 19 03:55:28 debian goes.vnetd[8743]: seq: 1531997729
Jul 19 03:55:28 debian goes.vnetd[8743]: pid: 9370
Jul 19 03:55:28 debian goes.vnetd[8743]: flags: match|exclude, atomic|create
Jul 19 03:55:28 debian goes.vnetd[8743]: family: INET
Jul 19 03:55:28 debian goes.vnetd[8743]: srclen: 0
Jul 19 03:55:28 debian goes.vnetd[8743]: dstlen: 8
Jul 19 03:55:28 debian goes.vnetd[8743]: tos: 0
Jul 19 03:55:28 debian goes.vnetd[8743]: table: MAIN
Jul 19 03:55:28 debian goes.vnetd[8743]: protocol: BOOT
Jul 19 03:55:28 debian goes.vnetd[8743]: scope: Universe
Jul 19 03:55:28 debian goes.vnetd[8743]: type: UNICAST
Jul 19 03:55:28 debian goes.vnetd[8743]: DST: 10.0.0.0
Jul 19 03:55:28 debian goes.vnetd[8743]: OIF: 48
Jul 19 03:55:28 debian goes.vnetd[8743]: GATEWAY: 10.15.0.4
Jul 19 03:55:28 debian goes.vnetd[8743]: TABLE: 254
Jul 19 03:55:28 debian goes.vnetd[8743]: