]> git.proxmox.com Git - mirror_frr.git/blob - lib/mlag.c
Merge pull request #5778 from ton31337/fix/add_doc_for_ebgp_connected_route_check
[mirror_frr.git] / lib / mlag.c
1 /* mlag generic code.
2 * Copyright (C) 2018 Cumulus Networks, Inc.
3 * Donald Sharp
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 *
17 * You should have received a copy of the GNU General Public License
18 * along with FRR; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22 #include <zebra.h>
23
24 #include <mlag.h>
25
26 char *mlag_role2str(enum mlag_role role, char *buf, size_t size)
27 {
28 switch (role) {
29 case MLAG_ROLE_NONE:
30 snprintf(buf, size, "NONE");
31 break;
32 case MLAG_ROLE_PRIMARY:
33 snprintf(buf, size, "PRIMARY");
34 break;
35 case MLAG_ROLE_SECONDARY:
36 snprintf(buf, size, "SECONDARY");
37 break;
38 }
39
40 return buf;
41 }
42
43 char *mlag_lib_msgid_to_str(enum mlag_msg_type msg_type, char *buf, size_t size)
44 {
45 switch (msg_type) {
46 case MLAG_REGISTER:
47 snprintf(buf, size, "Register");
48 break;
49 case MLAG_DEREGISTER:
50 snprintf(buf, size, "De-Register");
51 break;
52 case MLAG_MROUTE_ADD:
53 snprintf(buf, size, "Mroute add");
54 break;
55 case MLAG_MROUTE_DEL:
56 snprintf(buf, size, "Mroute del");
57 break;
58 case MLAG_DUMP:
59 snprintf(buf, size, "Mlag Replay");
60 break;
61 case MLAG_MROUTE_ADD_BULK:
62 snprintf(buf, size, "Mroute Add Batch");
63 break;
64 case MLAG_MROUTE_DEL_BULK:
65 snprintf(buf, size, "Mroute Del Batch");
66 break;
67 case MLAG_STATUS_UPDATE:
68 snprintf(buf, size, "Mlag Status");
69 break;
70 case MLAG_VXLAN_UPDATE:
71 snprintf(buf, size, "Mlag vxlan update");
72 break;
73 case MLAG_PEER_FRR_STATUS:
74 snprintf(buf, size, "Mlag Peer FRR Status");
75 break;
76 default:
77 snprintf(buf, size, "Unknown %d", msg_type);
78 break;
79 }
80 return buf;
81 }
82
83
84 int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg)
85 {
86 if (s == NULL || msg == NULL)
87 return -1;
88
89 STREAM_GETL(s, msg->msg_type);
90 STREAM_GETW(s, msg->data_len);
91 STREAM_GETW(s, msg->msg_cnt);
92 return 0;
93 stream_failure:
94 return -1;
95 }
96
97 int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg)
98 {
99 if (s == NULL || msg == NULL)
100 return -1;
101
102 STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ);
103 STREAM_GETL(s, msg->source_ip);
104 STREAM_GETL(s, msg->group_ip);
105 STREAM_GETL(s, msg->cost_to_rp);
106 STREAM_GETL(s, msg->owner_id);
107 STREAM_GETC(s, msg->am_i_dr);
108 STREAM_GETC(s, msg->am_i_dual_active);
109 STREAM_GETL(s, msg->vrf_id);
110 STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ);
111 return 0;
112 stream_failure:
113 return -1;
114 }
115
116 int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg)
117 {
118 if (s == NULL || msg == NULL)
119 return -1;
120
121 STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ);
122 STREAM_GETL(s, msg->source_ip);
123 STREAM_GETL(s, msg->group_ip);
124 STREAM_GETL(s, msg->owner_id);
125 STREAM_GETL(s, msg->vrf_id);
126 STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ);
127 return 0;
128 stream_failure:
129 return -1;
130 }
131
132 int mlag_lib_decode_mlag_status(struct stream *s, struct mlag_status *msg)
133 {
134 if (s == NULL || msg == NULL)
135 return -1;
136
137 STREAM_GET(msg->peerlink_rif, s, INTERFACE_NAMSIZ);
138 STREAM_GETL(s, msg->my_role);
139 STREAM_GETL(s, msg->peer_state);
140 return 0;
141 stream_failure:
142 return -1;
143 }
144
145 int mlag_lib_decode_vxlan_update(struct stream *s, struct mlag_vxlan *msg)
146 {
147 if (s == NULL || msg == NULL)
148 return -1;
149
150 STREAM_GETL(s, msg->anycast_ip);
151 STREAM_GETL(s, msg->local_ip);
152 return 0;
153
154 stream_failure:
155 return -1;
156 }
157
158 int mlag_lib_decode_frr_status(struct stream *s, struct mlag_frr_status *msg)
159 {
160 if (s == NULL || msg == NULL)
161 return -1;
162
163 STREAM_GETL(s, msg->frr_state);
164 return 0;
165 stream_failure:
166 return -1;
167 }