]>
Commit | Line | Data |
---|---|---|
ca10883e DS |
1 | /* |
2 | Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek | |
3 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | of this software and associated documentation files (the "Software"), to deal | |
6 | in the Software without restriction, including without limitation the rights | |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | copies of the Software, and to permit persons to whom the Software is | |
9 | furnished to do so, subject to the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in | |
12 | all copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | THE SOFTWARE. | |
21 | */ | |
22 | ||
b45ac5f5 DL |
23 | #ifdef HAVE_CONFIG_H |
24 | #include "config.h" | |
25 | #endif | |
26 | ||
ca10883e DS |
27 | #include "babel_filter.h" |
28 | #include "vty.h" | |
29 | #include "filter.h" | |
30 | #include "log.h" | |
31 | #include "plist.h" | |
32 | #include "distribute.h" | |
33 | #include "util.h" | |
34 | ||
35 | int | |
36 | babel_filter(int output, const unsigned char *prefix, unsigned short plen, | |
37 | unsigned int ifindex) | |
38 | { | |
39 | struct interface *ifp = if_lookup_by_index(ifindex, VRF_DEFAULT); | |
40 | babel_interface_nfo *babel_ifp = ifp ? babel_get_if_nfo(ifp) : NULL; | |
41 | struct prefix p; | |
42 | struct distribute *dist; | |
43 | struct access_list *alist; | |
44 | struct prefix_list *plist; | |
45 | int distribute; | |
46 | ||
47 | p.family = v4mapped(prefix) ? AF_INET : AF_INET6; | |
48 | p.prefixlen = v4mapped(prefix) ? plen - 96 : plen; | |
49 | if (p.family == AF_INET) { | |
50 | uchar_to_inaddr(&p.u.prefix4, prefix); | |
51 | distribute = output ? DISTRIBUTE_V4_OUT : DISTRIBUTE_V4_IN; | |
52 | } else { | |
53 | uchar_to_in6addr(&p.u.prefix6, prefix); | |
54 | distribute = output ? DISTRIBUTE_V6_OUT : DISTRIBUTE_V6_IN; | |
55 | } | |
56 | ||
57 | if (babel_ifp != NULL && babel_ifp->list[distribute]) { | |
58 | if (access_list_apply (babel_ifp->list[distribute], &p) | |
59 | == FILTER_DENY) { | |
60 | debugf(BABEL_DEBUG_FILTER, | |
61 | "%s/%d filtered by distribute %s", | |
62 | p.family == AF_INET ? | |
63 | inet_ntoa(p.u.prefix4) : | |
64 | inet6_ntoa (p.u.prefix6), | |
65 | p.prefixlen, | |
66 | output ? "out" : "in"); | |
67 | return INFINITY; | |
68 | } | |
69 | } | |
70 | if (babel_ifp != NULL && babel_ifp->prefix[distribute]) { | |
71 | if (prefix_list_apply (babel_ifp->prefix[distribute], &p) | |
72 | == PREFIX_DENY) { | |
73 | debugf(BABEL_DEBUG_FILTER, "%s/%d filtered by distribute %s", | |
74 | p.family == AF_INET ? | |
75 | inet_ntoa(p.u.prefix4) : | |
76 | inet6_ntoa (p.u.prefix6), | |
77 | p.prefixlen, | |
78 | output ? "out" : "in"); | |
79 | return INFINITY; | |
80 | } | |
81 | } | |
82 | ||
83 | /* All interface filter check. */ | |
84 | dist = distribute_lookup (NULL); | |
85 | if (dist) { | |
86 | if (dist->list[distribute]) { | |
87 | alist = access_list_lookup (p.family, dist->list[distribute]); | |
88 | ||
89 | if (alist) { | |
90 | if (access_list_apply (alist, &p) == FILTER_DENY) { | |
91 | debugf(BABEL_DEBUG_FILTER,"%s/%d filtered by distribute %s", | |
92 | p.family == AF_INET ? | |
93 | inet_ntoa(p.u.prefix4) : | |
94 | inet6_ntoa (p.u.prefix6), | |
95 | p.prefixlen, | |
96 | output ? "out" : "in"); | |
97 | return INFINITY; | |
98 | } | |
99 | } | |
100 | } | |
101 | if (dist->prefix[distribute]) { | |
102 | plist = prefix_list_lookup (p.family, dist->prefix[distribute]); | |
103 | if (plist) { | |
104 | if (prefix_list_apply (plist, &p) == PREFIX_DENY) { | |
105 | debugf(BABEL_DEBUG_FILTER,"%s/%d filtered by distribute %s", | |
106 | p.family == AF_INET ? | |
107 | inet_ntoa(p.u.prefix4) : | |
108 | inet6_ntoa (p.u.prefix6), | |
109 | p.prefixlen, | |
110 | output ? "out" : "in"); | |
111 | return INFINITY; | |
112 | } | |
113 | } | |
114 | } | |
115 | } | |
116 | return 0; | |
117 | } |