]> git.proxmox.com Git - mirror_frr.git/blob - lib/mlag.c
Merge pull request #5927 from mjstapp/interval_string_api
[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 size_t *length)
86 {
87 #define LIB_MLAG_HDR_LENGTH 8
88 *length = stream_get_endp(s);
89
90 if (s == NULL || msg == NULL || *length < LIB_MLAG_HDR_LENGTH)
91 return -1;
92
93 *length -= LIB_MLAG_HDR_LENGTH;
94
95 STREAM_GETL(s, msg->msg_type);
96 STREAM_GETW(s, msg->data_len);
97 STREAM_GETW(s, msg->msg_cnt);
98
99 return 0;
100 stream_failure:
101 return -1;
102 }
103
104 #define MLAG_MROUTE_ADD_LENGTH \
105 (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4 + 1 + 1 + 4)
106
107 int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg,
108 size_t *length)
109 {
110 if (s == NULL || msg == NULL || *length < MLAG_MROUTE_ADD_LENGTH)
111 return -1;
112
113 STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ);
114 STREAM_GETL(s, msg->source_ip);
115 STREAM_GETL(s, msg->group_ip);
116 STREAM_GETL(s, msg->cost_to_rp);
117 STREAM_GETL(s, msg->owner_id);
118 STREAM_GETC(s, msg->am_i_dr);
119 STREAM_GETC(s, msg->am_i_dual_active);
120 STREAM_GETL(s, msg->vrf_id);
121 STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ);
122
123 return 0;
124 stream_failure:
125 return -1;
126 }
127
128 #define MLAG_MROUTE_DEL_LENGTH (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4)
129
130 int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg,
131 size_t *length)
132 {
133 if (s == NULL || msg == NULL || *length < MLAG_MROUTE_DEL_LENGTH)
134 return -1;
135
136 STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ);
137 STREAM_GETL(s, msg->source_ip);
138 STREAM_GETL(s, msg->group_ip);
139 STREAM_GETL(s, msg->owner_id);
140 STREAM_GETL(s, msg->vrf_id);
141 STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ);
142
143 return 0;
144 stream_failure:
145 return -1;
146 }
147
148 int mlag_lib_decode_mlag_status(struct stream *s, struct mlag_status *msg)
149 {
150 if (s == NULL || msg == NULL)
151 return -1;
152
153 STREAM_GET(msg->peerlink_rif, s, INTERFACE_NAMSIZ);
154 STREAM_GETL(s, msg->my_role);
155 STREAM_GETL(s, msg->peer_state);
156 return 0;
157 stream_failure:
158 return -1;
159 }
160
161 int mlag_lib_decode_vxlan_update(struct stream *s, struct mlag_vxlan *msg)
162 {
163 if (s == NULL || msg == NULL)
164 return -1;
165
166 STREAM_GETL(s, msg->anycast_ip);
167 STREAM_GETL(s, msg->local_ip);
168 return 0;
169
170 stream_failure:
171 return -1;
172 }
173
174 int mlag_lib_decode_frr_status(struct stream *s, struct mlag_frr_status *msg)
175 {
176 if (s == NULL || msg == NULL)
177 return -1;
178
179 STREAM_GETL(s, msg->frr_state);
180 return 0;
181 stream_failure:
182 return -1;
183 }