hnetd: switch to babeld instead of babels
[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 --- a/kernel_netlink.c
26 +++ b/kernel_netlink.c
27 @@ -1243,8 +1243,8 @@ filter_kernel_routes(struct nlmsghdr *nh
28 if(rc < 0)
29 return 0;
30
31 - if(martian_prefix(current_route->prefix, current_route->plen) ||
32 - martian_prefix(current_route->src_prefix, current_route->src_plen))
33 + if(martian_prefix(current_route->prefix, current_route->plen, 0) ||
34 + martian_prefix(current_route->src_prefix, current_route->src_plen, 1))
35 return 0;
36
37 /* Ignore default unreachable routes; no idea where they come from. */
38 @@ -1946,7 +1946,7 @@ filter_kernel_rules(struct nlmsghdr *nh,
39 kdebugf("filter_rules: from %s prio %d table %d\n",
40 format_prefix(src, src_plen), priority, table);
41
42 - if(martian_prefix(src, src_plen) || !has_priority)
43 + if(martian_prefix(src, src_plen, 1) || !has_priority)
44 return 0;
45
46 i = priority - src_table_prio;
47 --- a/route.c
48 +++ b/route.c
49 @@ -809,12 +809,12 @@ update_route(const unsigned char *id,
50 if(memcmp(id, myid, 8) == 0)
51 return NULL;
52
53 - if(martian_prefix(prefix, plen)) {
54 + if(martian_prefix(prefix, plen, 0)) {
55 fprintf(stderr, "Rejecting martian route to %s through %s.\n",
56 format_prefix(prefix, plen), format_address(nexthop));
57 return NULL;
58 }
59 - if(src_plen != 0 && martian_prefix(src_prefix, src_plen)) {
60 + if(src_plen != 0 && martian_prefix(src_prefix, src_plen, 1)) {
61 fprintf(stderr, "Rejecting martian route to %s from %s through %s.\n",
62 format_prefix(prefix, plen),
63 format_prefix(src_prefix, src_plen), format_eui64(id));
64 --- a/util.c
65 +++ b/util.c
66 @@ -437,13 +437,13 @@ wait_for_fd(int direction, int fd, int m
67 }
68
69 int
70 -martian_prefix(const unsigned char *prefix, int plen)
71 +martian_prefix(const unsigned char *prefix, int plen, int is_source)
72 {
73 return
74 (plen >= 8 && prefix[0] == 0xFF) ||
75 (plen >= 10 && prefix[0] == 0xFE && (prefix[1] & 0xC0) == 0x80) ||
76 (plen >= 128 && memcmp(prefix, zeroes, 15) == 0 &&
77 - (prefix[15] == 0 || prefix[15] == 1)) ||
78 + ((prefix[15] == 0 && !is_source) || prefix[15] == 1)) ||
79 (plen >= 96 && v4mapped(prefix) &&
80 ((plen >= 104 && (prefix[12] == 127 || prefix[12] == 0)) ||
81 (plen >= 100 && (prefix[12] & 0xE0) == 0xE0)));
82 --- a/util.h
83 +++ b/util.h
84 @@ -106,7 +106,7 @@ int parse_net(const char *net, unsigned
85 int *af_r);
86 int parse_eui64(const char *eui, unsigned char *eui_r);
87 int wait_for_fd(int direction, int fd, int msecs);
88 -int martian_prefix(const unsigned char *prefix, int plen) ATTRIBUTE ((pure));
89 +int martian_prefix(const unsigned char *prefix, int plen, int is_source) ATTRIBUTE ((pure));
90 int linklocal(const unsigned char *address) ATTRIBUTE ((pure));
91 int v4mapped(const unsigned char *address) ATTRIBUTE ((pure));
92 void v4tov6(unsigned char *dst, const unsigned char *src);
93 --- a/xroute.c
94 +++ b/xroute.c
95 @@ -264,7 +264,7 @@ check_xroutes(int send_updates)
96 /* Add any new routes */
97
98 for(i = 0; i < numroutes; i++) {
99 - if(martian_prefix(routes[i].prefix, routes[i].plen))
100 + if(martian_prefix(routes[i].prefix, routes[i].plen, 0))
101 continue;
102 metric = redistribute_filter(routes[i].prefix, routes[i].plen,
103 routes[i].src_prefix, routes[i].src_plen,