e92c9905ddba75fec8b291ba53821e28937859fb
[feed/routing.git] / babels / patches / 0001-Allow-routes-with-source-128-for-SAS-on-Linux.patch
1 From 3fdbb1f797ee9fe9260af92f5d7ea760684cd271 Mon Sep 17 00:00:00 2001
2 From: Steven Barth <steven@midlink.org>
3 Date: Tue, 18 Feb 2014 13:18:32 +0100
4 Subject: [PATCH] Allow routes with source ::/128 for SAS on Linux
5
6 Linux uses the source-address :: (unspecified) to lookup routes in the
7 routing table for connections that are not bound to a specific source
8 address (e.g. ping6 2001:db8::1). If all default routes are
9 source-restricted a command like above will result in a "Permission
10 denied" error and no packets are being sent. Adding a default route with
11 source ::/128 avoids this issue.
12
13 This patch excludes ::/128 from the "martian_prefix" check for source
14 prefixes and thus allows such auxiliary routes to be distributed.
15
16 Signed-off-by: Steven Barth <cyrus@openwrt.org>
17 ---
18 kernel_netlink.c | 4 ++--
19 route.c | 4 ++--
20 util.c | 4 ++--
21 util.h | 2 +-
22 xroute.c | 2 +-
23 5 files changed, 8 insertions(+), 8 deletions(-)
24
25 diff --git a/kernel_netlink.c b/kernel_netlink.c
26 index 8b9099c..2e174af 100644
27 --- a/kernel_netlink.c
28 +++ b/kernel_netlink.c
29 @@ -1236,8 +1236,8 @@ filter_kernel_routes(struct nlmsghdr *nh, void *data)
30 if(rc < 0)
31 return 0;
32
33 - if(martian_prefix(current_route->prefix, current_route->plen) ||
34 - martian_prefix(current_route->src_prefix, current_route->src_plen))
35 + if(martian_prefix(current_route->prefix, current_route->plen, 0) ||
36 + martian_prefix(current_route->src_prefix, current_route->src_plen, 1))
37 return 0;
38
39 /* Ignore default unreachable routes; no idea where they come from. */
40 diff --git a/route.c b/route.c
41 index a97e8ed..c709303 100644
42 --- a/route.c
43 +++ b/route.c
44 @@ -1371,12 +1371,12 @@ update_route(const unsigned char *id,
45 if(memcmp(id, myid, 8) == 0)
46 return NULL;
47
48 - if(martian_prefix(prefix, plen)) {
49 + if(martian_prefix(prefix, plen, 0)) {
50 fprintf(stderr, "Rejecting martian route to %s through %s.\n",
51 format_prefix(prefix, plen), format_address(id));
52 return NULL;
53 }
54 - if(src_plen != 0 && martian_prefix(src_prefix, src_plen)) {
55 + if(src_plen != 0 && martian_prefix(src_prefix, src_plen, 1)) {
56 fprintf(stderr, "Rejecting martian route to %s from %s through %s.\n",
57 format_prefix(prefix, plen),
58 format_prefix(src_prefix, src_plen), format_address(id));
59 diff --git a/util.c b/util.c
60 index cdb4ab2..80930e4 100644
61 --- a/util.c
62 +++ b/util.c
63 @@ -425,13 +425,13 @@ wait_for_fd(int direction, int fd, int msecs)
64 }
65
66 int
67 -martian_prefix(const unsigned char *prefix, int plen)
68 +martian_prefix(const unsigned char *prefix, int plen, int is_source)
69 {
70 return
71 (plen >= 8 && prefix[0] == 0xFF) ||
72 (plen >= 10 && prefix[0] == 0xFE && (prefix[1] & 0xC0) == 0x80) ||
73 (plen >= 128 && memcmp(prefix, zeroes, 15) == 0 &&
74 - (prefix[15] == 0 || prefix[15] == 1)) ||
75 + ((prefix[15] == 0 && !is_source) || prefix[15] == 1)) ||
76 (plen >= 96 && v4mapped(prefix) &&
77 ((plen >= 104 && (prefix[12] == 127 || prefix[12] == 0)) ||
78 (plen >= 100 && (prefix[12] & 0xE0) == 0xE0)));
79 diff --git a/util.h b/util.h
80 index 935481f..f399b8a 100644
81 --- a/util.h
82 +++ b/util.h
83 @@ -95,7 +95,7 @@ int parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r,
84 int *af_r);
85 int parse_eui64(const char *eui, unsigned char *eui_r);
86 int wait_for_fd(int direction, int fd, int msecs);
87 -int martian_prefix(const unsigned char *prefix, int plen) ATTRIBUTE ((pure));
88 +int martian_prefix(const unsigned char *prefix, int plen, int is_source) ATTRIBUTE ((pure));
89 int linklocal(const unsigned char *address) ATTRIBUTE ((pure));
90 int v4mapped(const unsigned char *address) ATTRIBUTE ((pure));
91 void v4tov6(unsigned char *dst, const unsigned char *src);
92 diff --git a/xroute.c b/xroute.c
93 index e8b3b11..e4bd12a 100644
94 --- a/xroute.c
95 +++ b/xroute.c
96 @@ -259,7 +259,7 @@ check_xroutes(int send_updates)
97 /* Add any new routes */
98
99 for(i = 0; i < numroutes; i++) {
100 - if(martian_prefix(routes[i].prefix, routes[i].plen))
101 + if(martian_prefix(routes[i].prefix, routes[i].plen, 0))
102 continue;
103 metric = redistribute_filter(routes[i].prefix, routes[i].plen,
104 routes[i].src_prefix, routes[i].src_plen,
105 --
106 1.8.5.3
107