google / google/gopacket

Invalid routing information

Open
#863 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

`Route()` method of `routing.router` struct returns invalid routing info. I have enabled wireguard VPN interface `wg0` and usual wireless adapter `wlp3s0` with ip `192.168.0.3` connected to `192.168.0.0/24` LAN network. For instance, I want to send raw packet to host with ip `192.168.0.25`.

`ip route get 192.168.0.25` returns the following:

```
192.168.0.25 dev wlp3s0 src 192.168.0.3 uid 1000
cache
```

So kernel routing algorithm selects `192.168.0.3` as source IP and `wlp3s0` as ethernet device to send packets to `192.168.0.25`. However, `Route()` method of `routing.New()` object selects `wg0` device and its IP address.

I assume that the main problem is that routing decision is based only on [routes sorted by Priority (`routeSlice`)](https://github.com/google/gopacket/blob/master/routing/routing.go#L132) without longest prefix match.

From [Guide to IP Layer Network Administration with Linux](http://linux-ip.net/linux-ip/routing-selection.html#routing-selection-adv):

>The kernel begins iterating by priority through the routing policy database. For each matching entry in the RPDB, the kernel will try to find a matching route to the destination IP address in the specified routing table using the aforementioned longest prefix match selection algorithm. When a matching destination is found, the kernel will select the matching route, and forward the packet. If no matching entry is found in the specified routing table, the kernel will pass to the next rule in the RPDB, until it finds a match or falls through the end of the RPDB and all consulted routing tables.

My `ip rule` output:

```
0: from all lookup local
32764: from all lookup main suppress_prefixlength 0
32765: not from all fwmark 0xca6c lookup 51820
32766: from all lookup main
32767: from all lookup default
```

In case of `192.168.0.25`, kernel selects 32764 rule and ignores all routes with zero mask. And in `main` table I have the following entry:

```
192.168.0.0/24 dev wlp3s0 proto kernel scope link src 192.168.0.3
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.