]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | #ifdef HAVE_CONFIG_H | |
24 | #include "config.h" | |
25 | #endif | |
26 | ||
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 = NULL; | |
43 | struct access_list *alist; | |
44 | struct prefix_list *plist; | |
45 | int distribute; | |
46 | struct babel *babel; | |
47 | ||
48 | p.family = v4mapped(prefix) ? AF_INET : AF_INET6; | |
49 | p.prefixlen = v4mapped(prefix) ? plen - 96 : plen; | |
50 | if (p.family == AF_INET) { | |
51 | uchar_to_inaddr(&p.u.prefix4, prefix); | |
52 | distribute = output ? DISTRIBUTE_V4_OUT : DISTRIBUTE_V4_IN; | |
53 | } else { | |
54 | uchar_to_in6addr(&p.u.prefix6, prefix); | |
55 | distribute = output ? DISTRIBUTE_V6_OUT : DISTRIBUTE_V6_IN; | |
56 | } | |
57 | ||
58 | if (babel_ifp != NULL && babel_ifp->list[distribute]) { | |
59 | if (access_list_apply (babel_ifp->list[distribute], &p) | |
60 | == FILTER_DENY) { | |
61 | debugf(BABEL_DEBUG_FILTER, | |
62 | "%s/%d filtered by distribute %s", | |
63 | p.family == AF_INET ? | |
64 | inet_ntoa(p.u.prefix4) : | |
65 | inet6_ntoa (p.u.prefix6), | |
66 | p.prefixlen, | |
67 | output ? "out" : "in"); | |
68 | return INFINITY; | |
69 | } | |
70 | } | |
71 | if (babel_ifp != NULL && babel_ifp->prefix[distribute]) { | |
72 | if (prefix_list_apply (babel_ifp->prefix[distribute], &p) | |
73 | == PREFIX_DENY) { | |
74 | debugf(BABEL_DEBUG_FILTER, "%s/%d filtered by distribute %s", | |
75 | p.family == AF_INET ? | |
76 | inet_ntoa(p.u.prefix4) : | |
77 | inet6_ntoa (p.u.prefix6), | |
78 | p.prefixlen, | |
79 | output ? "out" : "in"); | |
80 | return INFINITY; | |
81 | } | |
82 | } | |
83 | ||
84 | /* All interface filter check. */ | |
85 | babel = babel_lookup(); | |
86 | if (babel) | |
87 | dist = distribute_lookup (babel->distribute_ctx, NULL); | |
88 | if (dist) { | |
89 | if (dist->list[distribute]) { | |
90 | alist = access_list_lookup (p.family, dist->list[distribute]); | |
91 | ||
92 | if (alist) { | |
93 | if (access_list_apply (alist, &p) == FILTER_DENY) { | |
94 | debugf(BABEL_DEBUG_FILTER,"%s/%d filtered by distribute %s", | |
95 | p.family == AF_INET ? | |
96 | inet_ntoa(p.u.prefix4) : | |
97 | inet6_ntoa (p.u.prefix6), | |
98 | p.prefixlen, | |
99 | output ? "out" : "in"); | |
100 | return INFINITY; | |
101 | } | |
102 | } | |
103 | } | |
104 | if (dist->prefix[distribute]) { | |
105 | plist = prefix_list_lookup (p.family, dist->prefix[distribute]); | |
106 | if (plist) { | |
107 | if (prefix_list_apply (plist, &p) == PREFIX_DENY) { | |
108 | debugf(BABEL_DEBUG_FILTER,"%s/%d filtered by distribute %s", | |
109 | p.family == AF_INET ? | |
110 | inet_ntoa(p.u.prefix4) : | |
111 | inet6_ntoa (p.u.prefix6), | |
112 | p.prefixlen, | |
113 | output ? "out" : "in"); | |
114 | return INFINITY; | |
115 | } | |
116 | } | |
117 | } | |
118 | } | |
119 | return 0; | |
120 | } |