]>
Commit | Line | Data |
---|---|---|
6edbb8b2 DS |
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 | } | |
46c2687c | 42 | |
1e76492b | 43 | char *mlag_lib_msgid_to_str(enum mlag_msg_type msg_type, char *buf, size_t size) |
46c2687c SK |
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; | |
5c260548 DS |
76 | case MLAG_PIM_CFG_DUMP: |
77 | snprintf(buf, size, "Mlag Pim Configuration Dump"); | |
78 | break; | |
79 | case MLAG_MSG_NONE: | |
46c2687c SK |
80 | snprintf(buf, size, "Unknown %d", msg_type); |
81 | break; | |
82 | } | |
83 | return buf; | |
84 | } | |
85 | ||
86 | ||
83f8a12b SK |
87 | int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg, |
88 | size_t *length) | |
46c2687c | 89 | { |
83f8a12b | 90 | #define LIB_MLAG_HDR_LENGTH 8 |
d1ba1814 DS |
91 | if (s == NULL || msg == NULL) |
92 | return -1; | |
93 | ||
83f8a12b SK |
94 | *length = stream_get_endp(s); |
95 | ||
d1ba1814 | 96 | if (*length < LIB_MLAG_HDR_LENGTH) |
46c2687c SK |
97 | return -1; |
98 | ||
83f8a12b SK |
99 | *length -= LIB_MLAG_HDR_LENGTH; |
100 | ||
46c2687c SK |
101 | STREAM_GETL(s, msg->msg_type); |
102 | STREAM_GETW(s, msg->data_len); | |
103 | STREAM_GETW(s, msg->msg_cnt); | |
83f8a12b | 104 | |
46c2687c SK |
105 | return 0; |
106 | stream_failure: | |
107 | return -1; | |
108 | } | |
109 | ||
83f8a12b SK |
110 | #define MLAG_MROUTE_ADD_LENGTH \ |
111 | (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4 + 1 + 1 + 4) | |
112 | ||
113 | int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg, | |
114 | size_t *length) | |
46c2687c | 115 | { |
83f8a12b | 116 | if (s == NULL || msg == NULL || *length < MLAG_MROUTE_ADD_LENGTH) |
46c2687c SK |
117 | return -1; |
118 | ||
119 | STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ); | |
120 | STREAM_GETL(s, msg->source_ip); | |
121 | STREAM_GETL(s, msg->group_ip); | |
122 | STREAM_GETL(s, msg->cost_to_rp); | |
123 | STREAM_GETL(s, msg->owner_id); | |
124 | STREAM_GETC(s, msg->am_i_dr); | |
125 | STREAM_GETC(s, msg->am_i_dual_active); | |
126 | STREAM_GETL(s, msg->vrf_id); | |
127 | STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ); | |
83f8a12b | 128 | |
46c2687c SK |
129 | return 0; |
130 | stream_failure: | |
131 | return -1; | |
132 | } | |
133 | ||
83f8a12b SK |
134 | #define MLAG_MROUTE_DEL_LENGTH (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4) |
135 | ||
136 | int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg, | |
137 | size_t *length) | |
46c2687c | 138 | { |
83f8a12b | 139 | if (s == NULL || msg == NULL || *length < MLAG_MROUTE_DEL_LENGTH) |
46c2687c SK |
140 | return -1; |
141 | ||
142 | STREAM_GET(msg->vrf_name, s, VRF_NAMSIZ); | |
143 | STREAM_GETL(s, msg->source_ip); | |
144 | STREAM_GETL(s, msg->group_ip); | |
145 | STREAM_GETL(s, msg->owner_id); | |
146 | STREAM_GETL(s, msg->vrf_id); | |
147 | STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ); | |
83f8a12b | 148 | |
46c2687c SK |
149 | return 0; |
150 | stream_failure: | |
151 | return -1; | |
152 | } | |
153 | ||
1e76492b | 154 | int mlag_lib_decode_mlag_status(struct stream *s, struct mlag_status *msg) |
46c2687c SK |
155 | { |
156 | if (s == NULL || msg == NULL) | |
157 | return -1; | |
158 | ||
159 | STREAM_GET(msg->peerlink_rif, s, INTERFACE_NAMSIZ); | |
160 | STREAM_GETL(s, msg->my_role); | |
161 | STREAM_GETL(s, msg->peer_state); | |
162 | return 0; | |
163 | stream_failure: | |
164 | return -1; | |
165 | } | |
166 | ||
1e76492b | 167 | int mlag_lib_decode_vxlan_update(struct stream *s, struct mlag_vxlan *msg) |
46c2687c SK |
168 | { |
169 | if (s == NULL || msg == NULL) | |
170 | return -1; | |
171 | ||
172 | STREAM_GETL(s, msg->anycast_ip); | |
173 | STREAM_GETL(s, msg->local_ip); | |
174 | return 0; | |
175 | ||
176 | stream_failure: | |
177 | return -1; | |
178 | } | |
179 | ||
1e76492b | 180 | int mlag_lib_decode_frr_status(struct stream *s, struct mlag_frr_status *msg) |
46c2687c SK |
181 | { |
182 | if (s == NULL || msg == NULL) | |
183 | return -1; | |
184 | ||
185 | STREAM_GETL(s, msg->frr_state); | |
186 | return 0; | |
187 | stream_failure: | |
188 | return -1; | |
189 | } |