]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_l2.h
bgpd: Refactor subgroup_announce_table() to reuse an existing helpers
[mirror_frr.git] / zebra / zebra_l2.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Zebra Layer-2 interface Data structures and definitions
4 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
5 */
6
7 #ifndef _ZEBRA_L2_H
8 #define _ZEBRA_L2_H
9
10 #include <zebra.h>
11
12 #include "if.h"
13 #include "vlan.h"
14 #include "vxlan.h"
15 #include "zebra/zebra_vrf.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #define ZEBRA_BRIDGE_NO_ACTION (0)
22 #define ZEBRA_BRIDGE_MASTER_MAC_CHANGE (1 << 1)
23 #define ZEBRA_BRIDGE_MASTER_UP (1 << 2)
24
25 /* zebra L2 interface information - bridge slave (linkage to bridge) */
26 struct zebra_l2info_brslave {
27 ifindex_t bridge_ifindex; /* Bridge Master */
28 struct interface *br_if; /* Pointer to master */
29 ns_id_t ns_id; /* network namespace where bridge is */
30 };
31
32 struct zebra_l2info_bond {
33 struct list *mbr_zifs; /* slaves using this bond as a master */
34 };
35
36 struct zebra_l2_bridge_vlan {
37 vlanid_t vid;
38 struct zebra_evpn_access_bd *access_bd;
39 };
40
41 struct zebra_l2_bridge_if_ctx {
42 /* input */
43 struct zebra_if *zif;
44 int (*func)(struct zebra_if *zif, struct zebra_l2_bridge_vlan *vlan,
45 void *arg);
46
47 /* input-output */
48 void *arg;
49 };
50
51 struct zebra_l2_bridge_if {
52 uint8_t vlan_aware;
53 struct zebra_if *br_zif;
54 struct hash *vlan_table;
55 };
56
57 /* zebra L2 interface information - bridge interface */
58 struct zebra_l2info_bridge {
59 struct zebra_l2_bridge_if bridge;
60 };
61
62 /* zebra L2 interface information - VLAN interface */
63 struct zebra_l2info_vlan {
64 vlanid_t vid; /* VLAN id */
65 };
66
67 /* zebra L2 interface information - GRE interface */
68 struct zebra_l2info_gre {
69 struct in_addr vtep_ip; /* IFLA_GRE_LOCAL */
70 struct in_addr vtep_ip_remote; /* IFLA_GRE_REMOTE */
71 uint32_t ikey;
72 uint32_t okey;
73 ifindex_t ifindex_link; /* Interface index of interface
74 * linked with GRE
75 */
76 ns_id_t link_nsid;
77 };
78
79 struct zebra_vxlan_vni {
80 vni_t vni; /* VNI */
81 vlanid_t access_vlan; /* Access VLAN - for VLAN-aware bridge. */
82 struct in_addr mcast_grp;
83 };
84
85 enum {
86 ZEBRA_VXLAN_IF_VNI = 0, /* per vni vxlan if */
87 ZEBRA_VXLAN_IF_SVD /* single vxlan device */
88 };
89
90 struct zebra_vxlan_if_vlan_ctx {
91 vlanid_t vid;
92 struct zebra_vxlan_vni *vni;
93 };
94
95 struct zebra_vxlan_if_update_ctx {
96 uint16_t chgflags;
97 struct in_addr old_vtep_ip;
98 struct zebra_vxlan_vni old_vni;
99 struct hash *old_vni_table;
100 };
101
102 struct zebra_vxlan_if_ctx {
103 /* input */
104 struct zebra_if *zif;
105 int (*func)(struct zebra_if *zif, struct zebra_vxlan_vni *vni,
106 void *arg);
107
108 /* input-output */
109 void *arg;
110 };
111
112 struct zebra_vxlan_vni_info {
113 int iftype;
114 union {
115 struct zebra_vxlan_vni vni; /* per vni vxlan device vni info */
116 struct hash
117 *vni_table; /* table of vni's assocated with this if */
118 };
119 };
120
121 /* zebra L2 interface information - VXLAN interface */
122 struct zebra_l2info_vxlan {
123 struct zebra_vxlan_vni_info vni_info;
124 struct in_addr vtep_ip; /* Local tunnel IP */
125 ifindex_t ifindex_link; /* Interface index of interface
126 * linked with VXLAN
127 */
128 ns_id_t link_nsid;
129 };
130
131 struct zebra_l2info_bondslave {
132 ifindex_t bond_ifindex; /* Bridge Master */
133 struct interface *bond_if; /* Pointer to master */
134 };
135
136 union zebra_l2if_info {
137 struct zebra_l2info_bridge br;
138 struct zebra_l2info_vlan vl;
139 struct zebra_l2info_vxlan vxl;
140 struct zebra_l2info_gre gre;
141 };
142
143 /* NOTE: These macros are to be invoked only in the "correct" context.
144 * IOW, the macro VNI_FROM_ZEBRA_IF() will assume the interface is
145 * of type ZEBRA_IF_VXLAN.
146 */
147 #define VNI_INFO_FROM_ZEBRA_IF(zif) (&((zif)->l2info.vxl.vni_info))
148 #define IS_ZEBRA_VXLAN_IF_SVD(zif) \
149 ((zif)->l2info.vxl.vni_info.iftype == ZEBRA_VXLAN_IF_SVD)
150 #define IS_ZEBRA_VXLAN_IF_VNI(zif) \
151 ((zif)->l2info.vxl.vni_info.iftype == ZEBRA_VXLAN_IF_VNI)
152 #define VLAN_ID_FROM_ZEBRA_IF(zif) (zif)->l2info.vl.vid
153
154 #define BRIDGE_FROM_ZEBRA_IF(zif) (&((zif)->l2info.br.bridge))
155 #define IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif) \
156 ((zif)->l2info.br.bridge.vlan_aware == 1)
157
158 extern void zebra_l2_map_slave_to_bridge(struct zebra_l2info_brslave *br_slave,
159 struct zebra_ns *zns);
160 extern void
161 zebra_l2_unmap_slave_from_bridge(struct zebra_l2info_brslave *br_slave);
162 extern void zebra_l2_bridge_add_update(struct interface *ifp,
163 struct zebra_l2info_bridge *bridge_info,
164 int add);
165 extern void zebra_l2_bridge_del(struct interface *ifp);
166 extern void zebra_l2_vlanif_update(struct interface *ifp,
167 struct zebra_l2info_vlan *vlan_info);
168 extern void zebra_l2_greif_add_update(struct interface *ifp,
169 struct zebra_l2info_gre *vxlan_info,
170 int add);
171 extern void zebra_l2_vxlanif_add_update(struct interface *ifp,
172 struct zebra_l2info_vxlan *vxlan_info,
173 int add);
174 extern void zebra_l2_vxlanif_update_access_vlan(struct interface *ifp,
175 vlanid_t access_vlan);
176 extern void zebra_l2_greif_del(struct interface *ifp);
177 extern void zebra_l2_vxlanif_del(struct interface *ifp);
178 extern void zebra_l2if_update_bridge_slave(struct interface *ifp,
179 ifindex_t bridge_ifindex,
180 ns_id_t ns_id, uint8_t chgflags);
181
182 extern void zebra_l2if_update_bond_slave(struct interface *ifp,
183 ifindex_t bond_ifindex, bool bypass);
184 extern void zebra_vlan_bitmap_compute(struct interface *ifp,
185 uint32_t vid_start, uint16_t vid_end);
186 extern void zebra_vlan_mbr_re_eval(struct interface *ifp,
187 bitfield_t vlan_bitmap);
188 extern void zebra_l2if_update_bond(struct interface *ifp, bool add);
189 extern void zebra_l2if_update_bridge(struct interface *ifp, uint8_t chgflags);
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif /* _ZEBRA_L2_H */