From b41b3f7bf1dee6e7c2817a63452e725d764a38a1 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 11 Jun 2019 15:35:28 +0200 Subject: [PATCH] lib/clippy: expand some macros At least the "easy" cases of macros work. Signed-off-by: David Lamparter --- python/clidef.py | 50 ++++++++++++++++++++++++++++++++++++++--------- zebra/zebra_vty.c | 15 ++++---------- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/python/clidef.py b/python/clidef.py index be68001310..85464a62d4 100644 --- a/python/clidef.py +++ b/python/clidef.py @@ -201,7 +201,27 @@ def get_always_args(token, always_args, args = [], stack = []): for nexttkn in token.next(): get_always_args(nexttkn, always_args, args, stack) -def process_file(fn, ofd, dumpfd, all_defun): +class Macros(dict): + def load(self, filename): + filedata = clippy.parse(filename) + for entry in filedata['data']: + if entry['type'] != 'PREPROC': + continue + ppdir = entry['line'].lstrip().split(None, 1) + if ppdir[0] != 'define' or len(ppdir) != 2: + continue + ppdef = ppdir[1].split(None, 1) + name = ppdef[0] + if '(' in name: + continue + val = ppdef[1] if len(ppdef) == 2 else '' + + val = val.strip(' \t\n\\') + if name in self: + sys.stderr.write('warning: macro %s redefined!\n' % (name)) + self[name] = val + +def process_file(fn, ofd, dumpfd, all_defun, macros): errors = 0 filedata = clippy.parse(fn) @@ -213,15 +233,21 @@ def process_file(fn, ofd, dumpfd, all_defun): continue cmddef = entry['args'][2] + cmddefx = [] for i in cmddef: - if not (i.startswith('"') and i.endswith('"')): - sys.stderr.write('%s:%d: DEFPY command string not parseable (%r)\n' % (fn, entry['lineno'], cmddef)) - errors += 1 - cmddef = None - break - if cmddef is None: + while i in macros: + i = macros[i] + if i.startswith('"') and i.endswith('"'): + cmddefx.append(i[1:-1]) + continue + + sys.stderr.write('%s:%d: DEFPY command string not parseable (%r)\n' % (fn, entry['lineno'], cmddef)) + errors += 1 + cmddefx = None + break + if cmddefx is None: continue - cmddef = ''.join([i[1:-1] for i in cmddef]) + cmddef = ''.join([i for i in cmddefx]) graph = clippy.Graph(cmddef) args = OrderedDict() @@ -320,7 +346,13 @@ if __name__ == '__main__': if args.show: dumpfd = sys.stderr - errors = process_file(args.cfile, ofd, dumpfd, args.all_defun) + macros = Macros() + macros.load('lib/route_types.h') + macros.load('lib/command.h') + # sigh :( + macros['PROTO_REDIST_STR'] = 'FRR_REDIST_STR_ISISD' + + errors = process_file(args.cfile, ofd, dumpfd, args.all_defun, macros) if errors != 0: sys.exit(1) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 257fb168d2..1f8eec9cad 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -2172,7 +2172,7 @@ DEFPY (show_evpn_mac_vni_all_dad, DEFPY (show_evpn_mac_vni_dad, show_evpn_mac_vni_dad_cmd, - "show evpn mac vni " CMD_VNI_RANGE " duplicate" "[json]", + "show evpn mac vni " CMD_VNI_RANGE " duplicate [json]", SHOW_STR "EVPN\n" "MAC addresses\n" @@ -2182,10 +2182,8 @@ DEFPY (show_evpn_mac_vni_dad, JSON_STR) { struct zebra_vrf *zvrf; - vni_t vni; bool uj = use_json(argc, argv); - vni = strtoul(argv[4]->arg, NULL, 10); zvrf = zebra_vrf_get_evpn(); zebra_vxlan_print_macs_vni_dad(vty, zvrf, vni, uj); @@ -2195,7 +2193,7 @@ DEFPY (show_evpn_mac_vni_dad, DEFPY (show_evpn_neigh_vni_dad, show_evpn_neigh_vni_dad_cmd, - "show evpn arp-cache vni " CMD_VNI_RANGE "duplicate" "[json]", + "show evpn arp-cache vni " CMD_VNI_RANGE "duplicate [json]", SHOW_STR "EVPN\n" "ARP and ND cache\n" @@ -2205,10 +2203,8 @@ DEFPY (show_evpn_neigh_vni_dad, JSON_STR) { struct zebra_vrf *zvrf; - vni_t vni; bool uj = use_json(argc, argv); - vni = strtoul(argv[4]->arg, NULL, 10); zvrf = zebra_vrf_get_evpn(); zebra_vxlan_print_neigh_vni_dad(vty, zvrf, vni, uj); return CMD_SUCCESS; @@ -2387,7 +2383,7 @@ DEFUN (show_pbr_iptable, DEFPY (clear_evpn_dup_addr, clear_evpn_dup_addr_cmd, - "clear evpn dup-addr vni ]>", + "clear evpn dup-addr vni ]>", CLEAR_STR "EVPN\n" "Duplicate address \n" @@ -2401,15 +2397,12 @@ DEFPY (clear_evpn_dup_addr, "IPv6 address\n") { struct zebra_vrf *zvrf; - vni_t vni = 0; struct ipaddr host_ip = {.ipa_type = IPADDR_NONE }; struct ethaddr mac_addr; int ret = CMD_SUCCESS; zvrf = zebra_vrf_get_evpn(); - if (vni_val) { - vni = strtoul(vni_val, NULL, 10); - + if (vni_str) { if (mac_val) { prefix_str2mac(mac_val, &mac_addr); ret = zebra_vxlan_clear_dup_detect_vni_mac(vty, zvrf, -- 2.39.5