]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/rfapi_descriptor_rfp_utils.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / bgpd / rfapi / rfapi_descriptor_rfp_utils.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 *
4 * Copyright 2009-2016, LabN Consulting, L.L.C.
5 *
6 */
7
8 #include "lib/zebra.h"
9 #include "lib/prefix.h"
10 #include "lib/table.h"
11 #include "lib/vty.h"
12 #include "lib/memory.h"
13 #include "lib/log.h"
14
15 #include "bgpd/bgpd.h"
16
17 #include "bgpd/rfapi/rfapi.h"
18 #include "bgpd/rfapi/rfapi_private.h"
19 #include "bgpd/rfapi/rfapi_descriptor_rfp_utils.h"
20 #include "bgpd/rfapi/vnc_debug.h"
21
22
23 void *rfapi_create_generic(struct rfapi_ip_addr *vn, struct rfapi_ip_addr *un)
24 {
25 struct rfapi_descriptor *rfd;
26 rfd = XCALLOC(MTYPE_RFAPI_DESC, sizeof(struct rfapi_descriptor));
27 vnc_zlog_debug_verbose("%s: rfd=%p", __func__, rfd);
28 rfd->vn_addr = *vn;
29 rfd->un_addr = *un;
30 return (void *)rfd;
31 }
32
33 /*------------------------------------------
34 * rfapi_free_generic
35 *
36 * Compare two generic rfapi descriptors.
37 *
38 * input:
39 * grfd: rfapi descriptor returned by rfapi_open or rfapi_create_generic
40 *
41 * output:
42 *
43 * return value:
44 *
45 *------------------------------------------*/
46 void rfapi_free_generic(void *grfd)
47 {
48 struct rfapi_descriptor *rfd;
49 rfd = (struct rfapi_descriptor *)grfd;
50 XFREE(MTYPE_RFAPI_DESC, rfd);
51 }
52
53
54 /*------------------------------------------
55 * rfapi_compare_rfds
56 *
57 * Compare two generic rfapi descriptors.
58 *
59 * input:
60 * rfd1: rfapi descriptor returned by rfapi_open or rfapi_create_generic
61 * rfd2: rfapi descriptor returned by rfapi_open or rfapi_create_generic
62 *
63 * output:
64 *
65 * return value:
66 * 0 Mismatch
67 * 1 Match
68 *------------------------------------------*/
69 int rfapi_compare_rfds(void *rfd1, void *rfd2)
70 {
71 struct rfapi_descriptor *rrfd1, *rrfd2;
72 int match = 0;
73
74 rrfd1 = (struct rfapi_descriptor *)rfd1;
75 rrfd2 = (struct rfapi_descriptor *)rfd2;
76
77 if (rrfd1->vn_addr.addr_family == rrfd2->vn_addr.addr_family) {
78 if (rrfd1->vn_addr.addr_family == AF_INET)
79 match = IPV4_ADDR_SAME(&(rrfd1->vn_addr.addr.v4),
80 &(rrfd2->vn_addr.addr.v4));
81 else
82 match = IPV6_ADDR_SAME(&(rrfd1->vn_addr.addr.v6),
83 &(rrfd2->vn_addr.addr.v6));
84 }
85
86 /*
87 * If the VN addresses don't match in all forms,
88 * give up.
89 */
90 if (!match)
91 return 0;
92
93 /*
94 * do the process again for the UN addresses.
95 */
96 match = 0;
97 if (rrfd1->un_addr.addr_family == rrfd2->un_addr.addr_family) {
98 /* VN addresses match
99 * UN address families match
100 * now check the actual UN addresses
101 */
102 if (rrfd1->un_addr.addr_family == AF_INET)
103 match = IPV4_ADDR_SAME(&(rrfd1->un_addr.addr.v4),
104 &(rrfd2->un_addr.addr.v4));
105 else
106 match = IPV6_ADDR_SAME(&(rrfd1->un_addr.addr.v6),
107 &(rrfd2->un_addr.addr.v6));
108 }
109 return match;
110 }