]> git.proxmox.com Git - mirror_frr.git/blob - babeld/babel_filter.c
Merge pull request #12816 from gpnaveen/stc_rte_err_msg
[mirror_frr.git] / babeld / babel_filter.c
1 // SPDX-License-Identifier: MIT
2 /*
3 Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
4 */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include "babel_filter.h"
11 #include "vty.h"
12 #include "filter.h"
13 #include "log.h"
14 #include "plist.h"
15 #include "distribute.h"
16 #include "util.h"
17
18 int
19 babel_filter(int output, const unsigned char *prefix, unsigned short plen,
20 unsigned int ifindex)
21 {
22 struct interface *ifp = if_lookup_by_index(ifindex, VRF_DEFAULT);
23 babel_interface_nfo *babel_ifp = ifp ? babel_get_if_nfo(ifp) : NULL;
24 struct prefix p;
25 struct distribute *dist = NULL;
26 struct access_list *alist;
27 struct prefix_list *plist;
28 int distribute;
29 struct babel *babel;
30 afi_t family;
31
32 p.family = v4mapped(prefix) ? AF_INET : AF_INET6;
33 p.prefixlen = v4mapped(prefix) ? plen - 96 : plen;
34 if (p.family == AF_INET) {
35 uchar_to_inaddr(&p.u.prefix4, prefix);
36 distribute = output ? DISTRIBUTE_V4_OUT : DISTRIBUTE_V4_IN;
37 family = AFI_IP;
38 } else {
39 uchar_to_in6addr(&p.u.prefix6, prefix);
40 distribute = output ? DISTRIBUTE_V6_OUT : DISTRIBUTE_V6_IN;
41 family = AFI_IP6;
42 }
43
44 if (babel_ifp != NULL && babel_ifp->list[distribute]) {
45 if (access_list_apply (babel_ifp->list[distribute], &p)
46 == FILTER_DENY) {
47 debugf(BABEL_DEBUG_FILTER,
48 "%pFX filtered by distribute %s",
49 &p, output ? "out" : "in");
50 return INFINITY;
51 }
52 }
53 if (babel_ifp != NULL && babel_ifp->prefix[distribute]) {
54 if (prefix_list_apply (babel_ifp->prefix[distribute], &p)
55 == PREFIX_DENY) {
56 debugf(BABEL_DEBUG_FILTER, "%pFX filtered by distribute %s",
57 &p, output ? "out" : "in");
58 return INFINITY;
59 }
60 }
61
62 /* All interface filter check. */
63 babel = babel_lookup();
64 if (babel)
65 dist = distribute_lookup (babel->distribute_ctx, NULL);
66 if (dist) {
67 if (dist->list[distribute]) {
68 alist = access_list_lookup (family, dist->list[distribute]);
69
70 if (alist) {
71 if (access_list_apply (alist, &p) == FILTER_DENY) {
72 debugf(BABEL_DEBUG_FILTER,"%pFX filtered by distribute %s",
73 &p, output ? "out" : "in");
74 return INFINITY;
75 }
76 }
77 }
78 if (dist->prefix[distribute]) {
79 plist = prefix_list_lookup (family, dist->prefix[distribute]);
80 if (plist) {
81 if (prefix_list_apply (plist, &p) == PREFIX_DENY) {
82 debugf(BABEL_DEBUG_FILTER,"%pFX filtered by distribute %s",
83 &p, output ? "out" : "in");
84 return INFINITY;
85 }
86 }
87 }
88 }
89 return 0;
90 }