c9a6e8796dfd31e9774215f40f69b99735fb686c
[openwrt/openwrt.git] / package / network / services / ppp / patches / 340-populate_default_gateway.patch
1 pppd: Fill in default gateway on Linux
2
3 On Linux, when pppd creates the default route, it does not set the peer
4 address as gateway, leading to a default route without gateway address.
5
6 This behaviour breaks various downstream programs which attempt to infer
7 the default gateway IP address from the system default route entry.
8
9 This patch addresses the issue by filling in the peer address as gateway
10 when generating the default route entry.
11
12 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
13
14 --- a/pppd/sys-linux.c
15 +++ b/pppd/sys-linux.c
16 @@ -1710,6 +1710,9 @@ int sifdefaultroute (int unit, u_int32_t
17 memset (&rt, 0, sizeof (rt));
18 SET_SA_FAMILY (rt.rt_dst, AF_INET);
19
20 + SET_SA_FAMILY(rt.rt_gateway, AF_INET);
21 + SIN_ADDR(rt.rt_gateway) = gateway;
22 +
23 rt.rt_dev = ifname;
24 rt.rt_metric = dfl_route_metric + 1; /* +1 for binary compatibility */
25
26 @@ -1718,7 +1721,7 @@ int sifdefaultroute (int unit, u_int32_t
27 SIN_ADDR(rt.rt_genmask) = 0L;
28 }
29
30 - rt.rt_flags = RTF_UP;
31 + rt.rt_flags = RTF_UP | RTF_GATEWAY;
32 if (ioctl(sock_fd, SIOCADDRT, &rt) < 0) {
33 if (!ok_error(errno))
34 error("default route ioctl(SIOCADDRT): %m");