1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* frrscript encoders and decoders for data structures in Zebra
* Copyright (C) 2021 Donald Lee
*/
#include "zebra.h"
#include "zebra_script.h"
#ifdef HAVE_SCRIPTING
void zebra_script_init(void)
{
frrscript_names_add_function_name(ZEBRA_ON_RIB_PROCESS_HOOK_CALL);
}
void zebra_script_destroy(void)
{
frrscript_names_destroy();
}
void lua_pushnh_grp(lua_State *L, const struct nh_grp *nh_grp)
{
lua_newtable(L);
lua_pushinteger(L, nh_grp->id);
lua_setfield(L, -2, "id");
lua_pushinteger(L, nh_grp->weight);
lua_setfield(L, -2, "weight");
}
void lua_pushzebra_dplane_ctx(lua_State *L, const struct zebra_dplane_ctx *ctx)
{
lua_newtable(L);
lua_pushinteger(L, dplane_ctx_get_op(ctx));
lua_setfield(L, -2, "zd_op");
lua_pushinteger(L, dplane_ctx_get_status(ctx));
lua_setfield(L, -2, "zd_status");
lua_pushinteger(L, dplane_ctx_get_provider(ctx));
lua_setfield(L, -2, "zd_provider");
lua_pushinteger(L, dplane_ctx_get_vrf(ctx));
lua_setfield(L, -2, "zd_vrf_id");
lua_pushinteger(L, dplane_ctx_get_table(ctx));
lua_setfield(L, -2, "zd_table_id");
lua_pushstring(L, dplane_ctx_get_ifname(ctx));
lua_setfield(L, -2, "zd_ifname");
lua_pushinteger(L, dplane_ctx_get_ifindex(ctx));
lua_setfield(L, -2, "zd_ifindex");
switch (dplane_ctx_get_op(ctx)) {
case DPLANE_OP_ROUTE_INSTALL:
case DPLANE_OP_ROUTE_UPDATE:
case DPLANE_OP_ROUTE_DELETE:
case DPLANE_OP_ROUTE_NOTIFY:
case DPLANE_OP_NH_INSTALL:
case DPLANE_OP_NH_UPDATE:
case DPLANE_OP_NH_DELETE:
/* rinfo */
lua_newtable(L);
{
lua_pushprefix(L, dplane_ctx_get_dest(ctx));
lua_setfield(L, -2, "zd_dest");
const struct prefix *src_pfx = dplane_ctx_get_src(ctx);
if (src_pfx) {
lua_pushprefix(L, src_pfx);
lua_setfield(L, -2, "zd_src");
}
lua_pushinteger(L, dplane_ctx_get_afi(ctx));
lua_setfield(L, -2, "zd_afi");
lua_pushinteger(L, dplane_ctx_get_safi(ctx));
lua_setfield(L, -2, "zd_safi");
lua_pushinteger(L, dplane_ctx_get_type(ctx));
lua_setfield(L, -2, "zd_type");
lua_pushinteger(L, dplane_ctx_get_old_type(ctx));
lua_setfield(L, -2, "zd_old_type");
lua_pushinteger(L, dplane_ctx_get_tag(ctx));
lua_setfield(L, -2, "zd_tag");
lua_pushinteger(L, dplane_ctx_get_old_tag(ctx));
lua_setfield(L, -2, "zd_old_tag");
lua_pushinteger(L, dplane_ctx_get_metric(ctx));
lua_setfield(L, -2, "zd_metric");
lua_pushinteger(L, dplane_ctx_get_old_metric(ctx));
lua_setfield(L, -2, "zd_old_metric");
lua_pushinteger(L, dplane_ctx_get_instance(ctx));
lua_setfield(L, -2, "zd_instance");
lua_pushinteger(L, dplane_ctx_get_old_instance(ctx));
lua_setfield(L, -2, "zd_old_instance");
lua_pushinteger(L, dplane_ctx_get_distance(ctx));
lua_setfield(L, -2, "zd_distance");
lua_pushinteger(L, dplane_ctx_get_old_distance(ctx));
lua_setfield(L, -2, "zd_old_distance");
lua_pushinteger(L, dplane_ctx_get_mtu(ctx));
lua_setfield(L, -2, "zd_mtu");
lua_pushinteger(L, dplane_ctx_get_nh_mtu(ctx));
lua_setfield(L, -2, "zd_nexthop_mtu");
/* nhe */
lua_newtable(L);
{
lua_pushinteger(L, dplane_ctx_get_nhe_id(ctx));
lua_setfield(L, -2, "id");
lua_pushinteger(L,
dplane_ctx_get_old_nhe_id(ctx));
lua_setfield(L, -2, "old_id");
lua_pushinteger(L, dplane_ctx_get_nhe_afi(ctx));
lua_setfield(L, -2, "afi");
lua_pushinteger(L,
dplane_ctx_get_nhe_vrf_id(ctx));
lua_setfield(L, -2, "vrf_id");
lua_pushinteger(L,
dplane_ctx_get_nhe_type(ctx));
lua_setfield(L, -2, "type");
lua_pushnexthop_group(
L, dplane_ctx_get_nhe_ng(ctx));
lua_setfield(L, -2, "ng");
lua_pushnh_grp(L,
dplane_ctx_get_nhe_nh_grp(ctx));
lua_setfield(L, -2, "nh_grp");
lua_pushinteger(
L,
dplane_ctx_get_nhe_nh_grp_count(ctx));
lua_setfield(L, -2, "nh_grp_count");
}
lua_setfield(L, -2, "nhe");
lua_pushinteger(L, dplane_ctx_get_nhg_id(ctx));
lua_setfield(L, -2, "zd_nhg_id");
lua_pushnexthop_group(L, dplane_ctx_get_ng(ctx));
lua_setfield(L, -2, "zd_ng");
lua_pushnexthop_group(L, dplane_ctx_get_backup_ng(ctx));
lua_setfield(L, -2, "backup_ng");
lua_pushnexthop_group(L, dplane_ctx_get_old_ng(ctx));
lua_setfield(L, -2, "zd_old_ng");
lua_pushnexthop_group(
L, dplane_ctx_get_old_backup_ng(ctx));
lua_setfield(L, -2, "old_backup_ng");
}
lua_setfield(L, -2, "rinfo");
break;
case DPLANE_OP_LSP_INSTALL:
case DPLANE_OP_LSP_UPDATE:
case DPLANE_OP_LSP_DELETE:
case DPLANE_OP_LSP_NOTIFY:
lua_pushinteger(L, (int)dplane_ctx_get_in_label(ctx));
lua_setfield(L, -2, "label");
break;
case DPLANE_OP_PW_INSTALL:
case DPLANE_OP_PW_UNINSTALL:
/* pw*/
lua_newtable(L);
{
lua_pushinteger(L, dplane_ctx_get_pw_type(ctx));
lua_setfield(L, -2, "type");
lua_pushinteger(L, dplane_ctx_get_pw_af(ctx));
lua_setfield(L, -2, "af");
lua_pushinteger(L, dplane_ctx_get_pw_status(ctx));
lua_setfield(L, -2, "status");
lua_pushinteger(L, dplane_ctx_get_pw_flags(ctx));
lua_setfield(L, -2, "flags");
lua_pushinteger(L, dplane_ctx_get_pw_local_label(ctx));
lua_setfield(L, -2, "local_label");
lua_pushinteger(L, dplane_ctx_get_pw_remote_label(ctx));
lua_setfield(L, -2, "remote_label");
}
lua_setfield(L, -2, "pw");
break;
case DPLANE_OP_SYS_ROUTE_ADD:
case DPLANE_OP_SYS_ROUTE_DELETE:
/* nothing to encode */
break;
case DPLANE_OP_MAC_INSTALL:
case DPLANE_OP_MAC_DELETE:
/* macinfo */
lua_newtable(L);
{
lua_pushinteger(L, dplane_ctx_mac_get_vlan(ctx));
lua_setfield(L, -2, "vid");
lua_pushinteger(L, dplane_ctx_mac_get_br_ifindex(ctx));
lua_setfield(L, -2, "br_ifindex");
lua_pushethaddr(L, dplane_ctx_mac_get_addr(ctx));
lua_setfield(L, -2, "mac");
lua_pushinaddr(L, dplane_ctx_mac_get_vtep_ip(ctx));
lua_setfield(L, -2, "vtep_ip");
lua_pushinteger(L, dplane_ctx_mac_is_sticky(ctx));
lua_setfield(L, -2, "is_sticky");
lua_pushinteger(L, dplane_ctx_mac_get_nhg_id(ctx));
lua_setfield(L, -2, "nhg_id");
lua_pushinteger(L,
dplane_ctx_mac_get_update_flags(ctx));
lua_setfield(L, -2, "update_flags");
}
lua_setfield(L, -2, "macinfo");
break;
case DPLANE_OP_RULE_ADD:
case DPLANE_OP_RULE_DELETE:
case DPLANE_OP_RULE_UPDATE:
/* rule */
lua_newtable(L);
{
lua_pushinteger(L, dplane_ctx_rule_get_sock(ctx));
lua_setfield(L, -2, "sock");
lua_pushinteger(L, dplane_ctx_rule_get_unique(ctx));
lua_setfield(L, -2, "unique");
lua_pushinteger(L, dplane_ctx_rule_get_seq(ctx));
lua_setfield(L, -2, "seq");
lua_pushstring(L, dplane_ctx_rule_get_ifname(ctx));
lua_setfield(L, -2, "ifname");
lua_pushinteger(L, dplane_ctx_rule_get_priority(ctx));
lua_setfield(L, -2, "priority");
lua_pushinteger(L,
dplane_ctx_rule_get_old_priority(ctx));
lua_setfield(L, -2, "old_priority");
lua_pushinteger(L, dplane_ctx_rule_get_table(ctx));
lua_setfield(L, -2, "table");
lua_pushinteger(L, dplane_ctx_rule_get_old_table(ctx));
lua_setfield(L, -2, "old_table");
lua_pushinteger(L, dplane_ctx_rule_get_filter_bm(ctx));
lua_setfield(L, -2, "filter_bm");
lua_pushinteger(L,
dplane_ctx_rule_get_old_filter_bm(ctx));
lua_setfield(L, -2, "old_filter_bm");
lua_pushinteger(L, dplane_ctx_rule_get_fwmark(ctx));
lua_setfield(L, -2, "fwmark");
lua_pushinteger(L, dplane_ctx_rule_get_old_fwmark(ctx));
lua_setfield(L, -2, "old_fwmark");
lua_pushinteger(L, dplane_ctx_rule_get_dsfield(ctx));
lua_setfield(L, -2, "dsfield");
lua_pushinteger(L,
dplane_ctx_rule_get_old_dsfield(ctx));
lua_setfield(L, -2, "old_dsfield");
lua_pushinteger(L, dplane_ctx_rule_get_ipproto(ctx));
lua_setfield(L, -2, "ip_proto");
lua_pushinteger(L,
dplane_ctx_rule_get_old_ipproto(ctx));
lua_setfield(L, -2, "old_ip_proto");
lua_pushprefix(L, dplane_ctx_rule_get_src_ip(ctx));
lua_setfield(L, -2, "src_ip");
lua_pushprefix(L, dplane_ctx_rule_get_old_src_ip(ctx));
lua_setfield(L, -2, "old_src_ip");
lua_pushprefix(L, dplane_ctx_rule_get_dst_ip(ctx));
lua_setfield(L, -2, "dst_ip");
lua_pushprefix(L, dplane_ctx_rule_get_old_dst_ip(ctx));
lua_setfield(L, -2, "old_dst_ip");
}
lua_setfield(L, -2, "rule");
break;
case DPLANE_OP_IPTABLE_ADD:
case DPLANE_OP_IPTABLE_DELETE: {
struct zebra_pbr_iptable iptable;
dplane_ctx_get_pbr_iptable(ctx, &iptable);
/* iptable */
lua_newtable(L);
{
lua_pushinteger(L, iptable.sock);
lua_setfield(L, -2, "sock");
lua_pushinteger(L, iptable.vrf_id);
lua_setfield(L, -2, "vrf_id");
lua_pushinteger(L, iptable.unique);
lua_setfield(L, -2, "unique");
lua_pushinteger(L, iptable.type);
lua_setfield(L, -2, "type");
lua_pushinteger(L, iptable.filter_bm);
lua_setfield(L, -2, "filter_bm");
lua_pushinteger(L, iptable.fwmark);
lua_setfield(L, -2, "fwmark");
lua_pushinteger(L, iptable.action);
lua_setfield(L, -2, "action");
lua_pushinteger(L, iptable.pkt_len_min);
lua_setfield(L, -2, "pkt_len_min");
lua_pushinteger(L, iptable.pkt_len_max);
lua_setfield(L, -2, "pkt_len_max");
lua_pushinteger(L, iptable.tcp_flags);
lua_setfield(L, -2, "tcp_flags");
lua_pushinteger(L, iptable.dscp_value);
lua_setfield(L, -2, "dscp_value");
lua_pushinteger(L, iptable.fragment);
lua_setfield(L, -2, "fragment");
lua_pushinteger(L, iptable.protocol);
lua_setfield(L, -2, "protocol");
lua_pushinteger(L, iptable.nb_interface);
lua_setfield(L, -2, "nb_interface");
lua_pushinteger(L, iptable.flow_label);
lua_setfield(L, -2, "flow_label");
lua_pushinteger(L, iptable.family);
lua_setfield(L, -2, "family");
lua_pushstring(L, iptable.ipset_name);
lua_setfield(L, -2, "ipset_name");
}
lua_setfield(L, -2, "iptable");
break;
}
case DPLANE_OP_IPSET_ADD:
case DPLANE_OP_IPSET_DELETE:
case DPLANE_OP_IPSET_ENTRY_ADD:
case DPLANE_OP_IPSET_ENTRY_DELETE: {
struct zebra_pbr_ipset ipset;
dplane_ctx_get_pbr_ipset(ctx, &ipset);
/* ipset */
lua_newtable(L);
{
lua_pushinteger(L, ipset.sock);
lua_setfield(L, -2, "sock");
lua_pushinteger(L, ipset.vrf_id);
lua_setfield(L, -2, "vrf_id");
lua_pushinteger(L, ipset.unique);
lua_setfield(L, -2, "unique");
lua_pushinteger(L, ipset.type);
lua_setfield(L, -2, "type");
lua_pushinteger(L, ipset.family);
lua_setfield(L, -2, "family");
lua_pushstring(L, ipset.ipset_name);
lua_setfield(L, -2, "ipset_name");
}
lua_setfield(L, -2, "ipset");
break;
}
case DPLANE_OP_NEIGH_INSTALL:
case DPLANE_OP_NEIGH_UPDATE:
case DPLANE_OP_NEIGH_DELETE:
case DPLANE_OP_NEIGH_DISCOVER:
case DPLANE_OP_NEIGH_IP_INSTALL:
case DPLANE_OP_NEIGH_IP_DELETE:
/* neigh */
lua_newtable(L);
{
lua_pushipaddr(L, dplane_ctx_neigh_get_ipaddr(ctx));
lua_setfield(L, -2, "ip_addr");
/* link */
lua_newtable(L);
{
lua_pushethaddr(L,
dplane_ctx_neigh_get_mac(ctx));
lua_setfield(L, -2, "mac");
lua_pushipaddr(
L, dplane_ctx_neigh_get_link_ip(ctx));
lua_setfield(L, -2, "ip_addr");
}
lua_setfield(L, -2, "link");
lua_pushinteger(L, dplane_ctx_neigh_get_flags(ctx));
lua_setfield(L, -2, "flags");
lua_pushinteger(L, dplane_ctx_neigh_get_state(ctx));
lua_setfield(L, -2, "state");
lua_pushinteger(L,
dplane_ctx_neigh_get_update_flags(ctx));
lua_setfield(L, -2, "update_flags");
}
lua_setfield(L, -2, "neigh");
break;
case DPLANE_OP_VTEP_ADD:
case DPLANE_OP_VTEP_DELETE:
break;
case DPLANE_OP_BR_PORT_UPDATE:
/* br_port */
lua_newtable(L);
{
lua_pushinteger(
L, dplane_ctx_get_br_port_sph_filter_cnt(ctx));
lua_setfield(L, -2, "sph_filter_cnt");
lua_pushinteger(L, dplane_ctx_get_br_port_flags(ctx));
lua_setfield(L, -2, "flags");
lua_pushinteger(
L, dplane_ctx_get_br_port_backup_nhg_id(ctx));
lua_setfield(L, -2, "backup_nhg_id");
}
lua_setfield(L, -2, "br_port");
break;
case DPLANE_OP_NEIGH_TABLE_UPDATE:
/* neightable */
lua_newtable(L);
{
lua_pushinteger(L,
dplane_ctx_neightable_get_family(ctx));
lua_setfield(L, -2, "family");
lua_pushinteger(
L, dplane_ctx_neightable_get_app_probes(ctx));
lua_setfield(L, -2, "app_probes");
lua_pushinteger(
L, dplane_ctx_neightable_get_mcast_probes(ctx));
lua_setfield(L, -2, "ucast_probes");
lua_pushinteger(
L, dplane_ctx_neightable_get_ucast_probes(ctx));
lua_setfield(L, -2, "mcast_probes");
}
lua_setfield(L, -2, "neightable");
break;
case DPLANE_OP_GRE_SET:
/* gre */
lua_newtable(L);
{
lua_pushinteger(L,
dplane_ctx_gre_get_link_ifindex(ctx));
lua_setfield(L, -2, "link_ifindex");
lua_pushinteger(L, dplane_ctx_gre_get_mtu(ctx));
lua_setfield(L, -2, "mtu");
}
lua_setfield(L, -2, "gre");
break;
case DPLANE_OP_ADDR_INSTALL:
case DPLANE_OP_ADDR_UNINSTALL:
case DPLANE_OP_INTF_ADDR_ADD:
case DPLANE_OP_INTF_ADDR_DEL:
case DPLANE_OP_INTF_INSTALL:
case DPLANE_OP_INTF_UPDATE:
case DPLANE_OP_INTF_DELETE:
case DPLANE_OP_TC_QDISC_INSTALL:
case DPLANE_OP_TC_QDISC_UNINSTALL:
case DPLANE_OP_TC_CLASS_ADD:
case DPLANE_OP_TC_CLASS_DELETE:
case DPLANE_OP_TC_CLASS_UPDATE:
case DPLANE_OP_TC_FILTER_ADD:
case DPLANE_OP_TC_FILTER_DELETE:
case DPLANE_OP_TC_FILTER_UPDATE:
/* Not currently handled */
case DPLANE_OP_INTF_NETCONFIG: /*NYI*/
case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET:
case DPLANE_OP_NONE:
case DPLANE_OP_STARTUP_STAGE:
break;
} /* Dispatch by op code */
}
#endif /* HAVE_SCRIPTING */
|