]> git.proxmox.com Git - mirror_frr.git/blame - pimd/pim_vxlan.c
pimd: header changes for pim-vxlan staggered processing
[mirror_frr.git] / pimd / pim_vxlan.c
CommitLineData
b583b035
AK
1/* PIM support for VxLAN BUM flooding
2 *
3 * Copyright (C) 2019 Cumulus Networks, Inc.
4 *
5 * This file is part of FRR.
6 *
7 * FRR is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * FRR is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 */
21
22#include <zebra.h>
23
24#include <hash.h>
25#include <jhash.h>
26#include <log.h>
27#include <prefix.h>
28#include <vrf.h>
29
30#include "pimd.h"
31#include "pim_iface.h"
32#include "pim_memory.h"
33#include "pim_oil.h"
34#include "pim_register.h"
35#include "pim_str.h"
36#include "pim_upstream.h"
37#include "pim_ifchannel.h"
38#include "pim_nht.h"
39#include "pim_zebra.h"
40#include "pim_vxlan.h"
41
d889ab75
AK
42/* pim-vxlan global info */
43struct pim_vxlan vxlan_info, *pim_vxlan_p = &vxlan_info;
b583b035
AK
44
45/************************** vxlan SG cache management ************************/
46static unsigned int pim_vxlan_sg_hash_key_make(void *p)
47{
48 struct pim_vxlan_sg *vxlan_sg = p;
49
50 return (jhash_2words(vxlan_sg->sg.src.s_addr,
51 vxlan_sg->sg.grp.s_addr, 0));
52}
53
54static bool pim_vxlan_sg_hash_eq(const void *p1, const void *p2)
55{
56 const struct pim_vxlan_sg *sg1 = p1;
57 const struct pim_vxlan_sg *sg2 = p2;
58
59 return ((sg1->sg.src.s_addr == sg2->sg.src.s_addr)
60 && (sg1->sg.grp.s_addr == sg2->sg.grp.s_addr));
61}
62
63static struct pim_vxlan_sg *pim_vxlan_sg_new(struct pim_instance *pim,
64 struct prefix_sg *sg)
65{
66 struct pim_vxlan_sg *vxlan_sg;
67
68 vxlan_sg = XCALLOC(MTYPE_PIM_VXLAN_SG, sizeof(*vxlan_sg));
69
70 vxlan_sg->pim = pim;
71 vxlan_sg->sg = *sg;
72 pim_str_sg_set(sg, vxlan_sg->sg_str);
73
74 if (PIM_DEBUG_VXLAN)
75 zlog_debug("vxlan SG %s alloc", vxlan_sg->sg_str);
76
77 vxlan_sg = hash_get(pim->vxlan.sg_hash, vxlan_sg, hash_alloc_intern);
78
79 return vxlan_sg;
80}
81
82struct pim_vxlan_sg *pim_vxlan_sg_find(struct pim_instance *pim,
83 struct prefix_sg *sg)
84{
85 struct pim_vxlan_sg lookup;
86
87 lookup.sg = *sg;
88 return hash_lookup(pim->vxlan.sg_hash, &lookup);
89}
90
91struct pim_vxlan_sg *pim_vxlan_sg_add(struct pim_instance *pim,
92 struct prefix_sg *sg)
93{
94 struct pim_vxlan_sg *vxlan_sg;
95
96 vxlan_sg = pim_vxlan_sg_find(pim, sg);
97 if (vxlan_sg)
98 return vxlan_sg;
99
100 vxlan_sg = pim_vxlan_sg_new(pim, sg);
101
102 return vxlan_sg;
103}
104
105void pim_vxlan_sg_del(struct pim_instance *pim, struct prefix_sg *sg)
106{
107 struct pim_vxlan_sg *vxlan_sg;
108
109 vxlan_sg = pim_vxlan_sg_find(pim, sg);
110 if (!vxlan_sg)
111 return;
112
113 hash_release(vxlan_sg->pim->vxlan.sg_hash, vxlan_sg);
114
115 if (PIM_DEBUG_VXLAN)
116 zlog_debug("vxlan SG %s free", vxlan_sg->sg_str);
117
118 XFREE(MTYPE_PIM_VXLAN_SG, vxlan_sg);
119}
120
121void pim_vxlan_init(struct pim_instance *pim)
122{
123 char hash_name[64];
124
125 snprintf(hash_name, sizeof(hash_name),
126 "PIM %s vxlan SG hash", pim->vrf->name);
127 pim->vxlan.sg_hash = hash_create(pim_vxlan_sg_hash_key_make,
128 pim_vxlan_sg_hash_eq, hash_name);
129}
130
131void pim_vxlan_exit(struct pim_instance *pim)
132{
133 if (pim->vxlan.sg_hash) {
134 hash_clean(pim->vxlan.sg_hash, NULL);
135 hash_free(pim->vxlan.sg_hash);
136 pim->vxlan.sg_hash = NULL;
137 }
138}