zebra: add 'int idx_foo' argv index variables

Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
This commit is contained in:
Daniel Walton 2016-09-23 19:26:31 +00:00
parent 0a3e73dd27
commit 7c022376c8
9 changed files with 1395 additions and 408 deletions

View File

@ -4,6 +4,7 @@ import re
import sys import sys
import os import os
import subprocess import subprocess
from collections import OrderedDict
from copy import deepcopy from copy import deepcopy
from pprint import pformat, pprint from pprint import pformat, pprint
@ -156,7 +157,7 @@ def get_argv_translator(line_number, line):
return table return table
''' '''
def get_argv_variable_indexes(line_number, line): def get_command_string_variable_indexes(line_number, line):
indexes = {} indexes = {}
line = line.strip() line = line.strip()
@ -177,6 +178,230 @@ def get_argv_variable_indexes(line_number, line):
return (max_index, indexes) return (max_index, indexes)
def get_token_index_variable_name(line_number, token):
re_range = re.search('\(\d+-\d+\)', token)
if token.startswith('['):
assert token.endswith(']'), "Token %s should end with ]" % token
token = token[1:-1]
if token.startswith('<'):
assert token.endswith('>'), "Token %s should end with >" % token
token = token[1:-1]
if token == 'A.B.C.D':
return 'idx_ipv4'
elif token == 'A.B.C.D/M':
return 'idx_ipv4_prefixlen'
elif token == 'X:X::X:X':
return 'idx_ipv6'
elif token == 'X:X::X:X/M':
return 'idx_ipv6_prefixlen'
elif token == 'ASN:nn_or_IP-address:nn':
return 'idx_ext_community'
elif token == '.AA:NN':
return 'idx_community'
elif token == 'WORD':
return 'idx_word'
elif token == 'json':
return 'idx_json'
elif token == '.LINE':
return 'idx_regex'
elif token == 'A.B.C.D|INTERFACE':
return 'idx_ipv4_ifname'
elif token == 'A.B.C.D|INTERFACE|null0':
return 'idx_ipv4_ifname_null'
elif token == 'X:X::X:X|INTERFACE':
return 'idx_ipv6_ifname'
elif token == 'reject|blackhole':
return 'idx_reject_blackhole'
elif token == 'route-map NAME':
return 'idx_route_map'
elif token == 'recv|send|detail':
return 'idx_recv_send'
elif token == 'recv|send':
return 'idx_recv_send'
elif token == 'up|down':
return 'idx_up_down'
elif token == 'off-link':
return 'idx_off_link'
elif token == 'no-autoconfig':
return 'idx_no_autoconfig'
elif token == 'router-address':
return 'idx_router_address'
elif token == 'high|medium|low':
return 'idx_high_medium_low'
elif token == '(0-4294967295)|infinite':
return 'idx_number_infinite'
elif token == '(1-199)|(1300-2699)|WORD':
return 'idx_acl'
elif token == 'A.B.C.D|X:X::X:X':
return 'idx_ip'
elif token == 'urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix':
return 'idx_rpf_lookup_mode'
elif token in ('kernel|connected|static|rip|ospf|isis|pim|table',
'kernel|connected|static|ripng|ospf6|isis|table',
'kernel|connected|static|rip|isis|bgp|pim|table',
'kernel|connected|static|rip|ospf|isis|bgp|pim|table',
'kernel|connected|static|rip|ospf|isis|bgp|pim|table',
'kernel|connected|static|rip|ospf|isis|bgp|pim|table|any',
'kernel|connected|static|ripng|ospf6|isis|bgp|table|any',
'kernel|connected|static|ripng|ospf6|isis|bgp|table',
'kernel|connected|static|ospf6|isis|bgp|table',
'kernel|connected|static|ospf|isis|bgp|pim|table',
'kernel|connected|static|ripng|isis|bgp|table',
# '',
'bgp|ospf|rip|ripng|isis|ospf6|connected|system|kernel|static',
'kernel|connected|static|rip|ripng|ospf|ospf6|bgp|pim|table'):
return 'idx_protocol'
elif '|' in token:
raise Exception("%d: what variable name for %s" % (line_number, token))
elif re_range:
return 'idx_number'
elif token.upper() == token:
return 'idx_%s' % token.lower()
else:
raise Exception("%d: what variable name for %s" % (line_number, token))
def get_command_string_index_variable_table(line_number, line):
"""
Return a table that maps an index position to a variable name such as 'idx_ipv4'
"""
indexes = OrderedDict()
line = line.strip()
assert line.startswith('"'), "line does not start with \"\n%s" % (line)
assert line.endswith('",'), "line does not end with \",\n%s" % (line)
line = line[1:-2]
max_index = 0
for (token_index, token) in enumerate(line_to_tokens(line_number, line)):
if not token:
raise Exception("%d: empty token" % line_number)
if token_is_variable(line_number, token):
# print "%s is a token" % token
idx_variable_name = get_token_index_variable_name(line_number, token)
count = 0
for tmp in indexes.itervalues():
if tmp == idx_variable_name:
count += 1
elif re.search('^%s_\d+' % idx_variable_name, tmp):
count += 1
if count:
idx_variable_name = "%s_%d" % (idx_variable_name, count + 1)
indexes[token_index] = idx_variable_name
return indexes
def expand_command_string(line):
# in the middle
line = line.replace('" CMD_AS_RANGE "', '(1-4294967295)')
line = line.replace('" DYNAMIC_NEIGHBOR_LIMIT_RANGE "', '(1-5000)')
line = line.replace('" BGP_INSTANCE_CMD "', '<view|vrf> WORD')
line = line.replace('" BGP_INSTANCE_ALL_CMD "', '<view|vrf> all')
line = line.replace('" CMD_RANGE_STR(1, MULTIPATH_NUM) "', '(1-255)')
line = line.replace('" QUAGGA_IP_REDIST_STR_BGPD "', '<kernel|connected|static|rip|ospf|isis|pim|table>')
line = line.replace('" QUAGGA_IP6_REDIST_STR_BGPD "', '<kernel|connected|static|ripng|ospf6|isis|table>')
line = line.replace('" OSPF_LSA_TYPES_CMD_STR "', 'asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as')
line = line.replace('" QUAGGA_REDIST_STR_OSPFD "', '<kernel|connected|static|rip|isis|bgp|pim|table>')
line = line.replace('" VRF_CMD_STR "', 'vrf NAME')
line = line.replace('" VRF_ALL_CMD_STR "', 'vrf all')
line = line.replace('" QUAGGA_IP_PROTOCOL_MAP_STR_ZEBRA "', '<kernel|connected|static|rip|ospf|isis|bgp|pim|table|any>')
line = line.replace('" QUAGGA_IP6_PROTOCOL_MAP_STR_ZEBRA "', '<kernel|connected|static|ripng|ospf6|isis|bgp|table|any>')
line = line.replace('" QUAGGA_REDIST_STR_RIPNGD "', '<kernel|connected|static|ospf6|isis|bgp|table>')
line = line.replace('" QUAGGA_REDIST_STR_RIPD "', '<kernel|connected|static|ospf|isis|bgp|pim|table>')
line = line.replace('" QUAGGA_REDIST_STR_OSPF6D "', '<kernel|connected|static|ripng|isis|bgp|table>')
line = line.replace('" QUAGGA_REDIST_STR_ISISD "', '<kernel|connected|static|rip|ripng|ospf|ospf6|bgp|pim|table>')
line = line.replace('" LOG_FACILITIES "', '<kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>')
# endswith
line = line.replace('" CMD_AS_RANGE,', ' (1-4294967295)",')
line = line.replace('" DYNAMIC_NEIGHBOR_LIMIT_RANGE,', ' (1-5000)",')
line = line.replace('" BGP_INSTANCE_CMD,', ' <view|vrf> WORD",')
line = line.replace('" BGP_INSTANCE_ALL_CMD,', ' <view|vrf> all",')
line = line.replace('" CMD_RANGE_STR(1, MULTIPATH_NUM),', '(1-255)",')
line = line.replace('" CMD_RANGE_STR(1, MAXTTL),', '(1-255)",')
line = line.replace('" BFD_CMD_DETECT_MULT_RANGE BFD_CMD_MIN_RX_RANGE BFD_CMD_MIN_TX_RANGE,', '(2-255) (50-60000) (50-60000)",')
line = line.replace('" OSPF_LSA_TYPES_CMD_STR,',
' asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as",')
line = line.replace('" BGP_UPDATE_SOURCE_REQ_STR,', ' <A.B.C.D|X:X::X:X|WORD>",')
line = line.replace('" BGP_UPDATE_SOURCE_OPT_STR,', ' [A.B.C.D|X:X::X:X|WORD]",')
line = line.replace('" QUAGGA_IP_REDIST_STR_BGPD,', ' <kernel|connected|static|rip|ospf|isis|pim|table>",')
line = line.replace('" QUAGGA_IP6_REDIST_STR_BGPD,', ' <kernel|connected|static|ripng|ospf6|isis|table>",')
line = line.replace('" QUAGGA_REDIST_STR_OSPFD,', ' <kernel|connected|static|rip|isis|bgp|pim|table>",')
line = line.replace('" VRF_CMD_STR,', ' vrf NAME",')
line = line.replace('" VRF_ALL_CMD_STR,', ' vrf all",')
line = line.replace('" QUAGGA_IP_REDIST_STR_ZEBRA,', ' <kernel|connected|static|rip|ospf|isis|bgp|pim|table>",')
line = line.replace('" QUAGGA_IP6_REDIST_STR_ZEBRA,', ' <kernel|connected|static|ripng|ospf6|isis|bgp|table>",')
line = line.replace('" QUAGGA_IP_PROTOCOL_MAP_STR_ZEBRA,', ' <kernel|connected|static|rip|ospf|isis|bgp|pim|table|any>",')
line = line.replace('" QUAGGA_IP6_PROTOCOL_MAP_STR_ZEBRA,', ' <kernel|connected|static|ripng|ospf6|isis|bgp|table|any>",')
line = line.replace('" QUAGGA_REDIST_STR_RIPNGD,', ' <kernel|connected|static|ospf6|isis|bgp|table>",')
line = line.replace('" QUAGGA_REDIST_STR_RIPD,', ' <kernel|connected|static|ospf|isis|bgp|pim|table>",')
line = line.replace('" PIM_CMD_IP_MULTICAST_ROUTING,', ' ip multicast-routing",')
line = line.replace('" PIM_CMD_IP_IGMP_QUERY_INTERVAL,', ' ip igmp query-interval",')
line = line.replace('" PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC,', ' ip igmp query-max-response-time-dsec",')
line = line.replace('" PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME,', ' ip igmp query-max-response-time",')
line = line.replace('" QUAGGA_REDIST_STR_OSPF6D,', ' <kernel|connected|static|ripng|isis|bgp|table>",')
line = line.replace('" QUAGGA_REDIST_STR_ISISD,', ' <kernel|connected|static|rip|ripng|ospf|ospf6|bgp|pim|table>",')
line = line.replace('" LOG_FACILITIES,', ' <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",')
# startswith
line = line.replace('LISTEN_RANGE_CMD "', '"bgp listen range <A.B.C.D/M|X:X::X:X/M> ')
line = line.replace('NO_NEIGHBOR_CMD2 "', '"no neighbor <A.B.C.D|X:X::X:X|WORD> ')
line = line.replace('NEIGHBOR_CMD2 "', '"neighbor <A.B.C.D|X:X::X:X|WORD> ')
line = line.replace('NO_NEIGHBOR_CMD "', '"no neighbor <A.B.C.D|X:X::X:X> ')
line = line.replace('NEIGHBOR_CMD "', '"neighbor <A.B.C.D|X:X::X:X> ')
line = line.replace('PIM_CMD_NO "', '"no ')
line = line.replace('PIM_CMD_IP_IGMP_QUERY_INTERVAL "', '"ip igmp query-interval ')
line = line.replace('PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME "', '"ip igmp query-max-response-time ')
line = line.replace('PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC "', '"ip igmp query-max-response-time-dsec ')
# solo
line = line.replace('NO_NEIGHBOR_CMD2,', '"no neighbor <A.B.C.D|X:X::X:X|WORD>",')
line = line.replace('NEIGHBOR_CMD2,', '"neighbor <A.B.C.D|X:X::X:X|WORD>",')
line = line.replace('NO_NEIGHBOR_CMD,', '"no neighbor <A.B.C.D|X:X::X:X>",')
line = line.replace('NEIGHBOR_CMD,', '"neighbor <A.B.C.D|X:X::X:X>",')
line = line.replace('PIM_CMD_IP_MULTICAST_ROUTING,', '"ip multicast-routing",')
if line.rstrip().endswith('" ,'):
line = line.replace('" ,', '",')
return line
class DEFUN(object): class DEFUN(object):
def __init__(self, line_number, command_string_expanded, lines): def __init__(self, line_number, command_string_expanded, lines):
@ -216,14 +441,14 @@ DEFUN (no_bgp_maxmed_onstartup,
elif state == 'HELP': elif state == 'HELP':
if line.strip() == '{': if line.strip() == '{':
self.guts.append(line) # self.guts.append(line)
state = 'BODY' state = 'BODY'
else: else:
self.help_strings.append(line) self.help_strings.append(line)
elif state == 'BODY': elif state == 'BODY':
if line.rstrip() == '}': if line.rstrip() == '}':
self.guts.append(line) # self.guts.append(line)
state = None state = None
else: else:
self.guts.append(line) self.guts.append(line)
@ -239,7 +464,7 @@ DEFUN (no_bgp_maxmed_onstartup,
return self.name return self.name
def sanity_check(self): def sanity_check(self):
(max_index, variable_indexes) = get_argv_variable_indexes(self.line_number, self.command_string_expanded) (max_index, variable_indexes) = get_command_string_variable_indexes(self.line_number, self.command_string_expanded)
# sanity check that each argv index matches a variable in the command string # sanity check that each argv index matches a variable in the command string
for line in self.guts: for line in self.guts:
@ -256,7 +481,6 @@ DEFUN (no_bgp_maxmed_onstartup,
def get_new_command_string(self): def get_new_command_string(self):
line = self.command_string line = self.command_string
# dwalton
# Change <1-255> to (1-255) # Change <1-255> to (1-255)
# Change (foo|bar) to <foo|bar> # Change (foo|bar) to <foo|bar>
# Change {wazzup} to [wazzup]....there shouldn't be many of these # Change {wazzup} to [wazzup]....there shouldn't be many of these
@ -284,18 +508,68 @@ DEFUN (no_bgp_maxmed_onstartup,
line = re_space.group(1) + ' '.join(line.split()) + re_space.group(2) line = re_space.group(1) + ' '.join(line.split()) + re_space.group(2)
return line return line
def get_used_idx_variables(self, idx_table):
used = {}
# sanity check that each argv index matches a variable in the command string
for line in self.guts:
if 'argv[' in line and '->arg' in line:
tmp_line = deepcopy(line)
re_argv = re.search('^.*?argv\[(\w+)\]->arg(.*)$', tmp_line)
while re_argv:
index = re_argv.group(1)
if index.isdigit():
index = int(index)
if index in idx_table:
used[index] = idx_table[index]
else:
print "%d: could not find idx variable for %d" % (self.line_number, index)
else:
for (key, value) in idx_table.iteritems():
if value == index:
used[key] = value
break
tmp_line = re_argv.group(2)
re_argv = re.search('^.*?argv\[(\w+)\]->arg(.*)$', tmp_line)
return used
def dump(self): def dump(self):
new_command_string = self.get_new_command_string()
new_command_string_expanded = expand_command_string(new_command_string)
lines = [] lines = []
lines.append("DEFUN (%s,\n" % self.name) lines.append("DEFUN (%s,\n" % self.name)
lines.append(" %s,\n" % self.name_cmd) lines.append(" %s,\n" % self.name_cmd)
lines.append(self.get_new_command_string()) lines.append(new_command_string)
lines.extend(self.help_strings) lines.extend(self.help_strings)
lines.extend(self.guts) lines.append('{\n')
# only print the variables that will be used else we get a compile error
idx_table = get_command_string_index_variable_table(self.line_number, new_command_string_expanded)
idx_table_used = self.get_used_idx_variables(idx_table)
for index in sorted(idx_table_used.keys()):
idx_variable = idx_table_used[index]
lines.append(" int %s = %d;\n" % (idx_variable, index))
# sanity check that each argv index matches a variable in the command string
for line in self.guts:
if line.startswith(' int idx_'):
pass
elif 'argv[' in line and '->arg' in line:
for (index, idx_variable) in idx_table.iteritems():
line = line.replace("argv[%d]->arg" % index, "argv[%s]->arg" % idx_variable)
lines.append(line)
else:
lines.append(line)
lines.append('}\n')
return ''.join(lines) return ''.join(lines)
def update_argvs(filename): def update_argvs(filename):
lines = [] lines = []
@ -334,78 +608,7 @@ def update_argvs(filename):
state = 'DEFUN_BODY' state = 'DEFUN_BODY'
elif line_number == defun_line_number + 2: elif line_number == defun_line_number + 2:
line = expand_command_string(line)
# in the middle
line = line.replace('" CMD_AS_RANGE "', '<1-4294967295>')
line = line.replace('" DYNAMIC_NEIGHBOR_LIMIT_RANGE "', '<1-5000>')
line = line.replace('" BGP_INSTANCE_CMD "', '(view|vrf) WORD')
line = line.replace('" BGP_INSTANCE_ALL_CMD "', '(view|vrf) all')
line = line.replace('" CMD_RANGE_STR(1, MULTIPATH_NUM) "', '<1-255>')
line = line.replace('" QUAGGA_IP_REDIST_STR_BGPD "', '(kernel|connected|static|rip|ospf|isis|pim|table)')
line = line.replace('" QUAGGA_IP6_REDIST_STR_BGPD "', '(kernel|connected|static|ripng|ospf6|isis|table)')
line = line.replace('" OSPF_LSA_TYPES_CMD_STR "', 'asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as')
line = line.replace('" QUAGGA_REDIST_STR_OSPFD "', '(kernel|connected|static|rip|isis|bgp|pim|table)')
line = line.replace('" VRF_CMD_STR "', 'vrf NAME')
line = line.replace('" VRF_ALL_CMD_STR "', 'vrf all')
line = line.replace('" QUAGGA_IP_PROTOCOL_MAP_STR_ZEBRA "', '(kernel|connected|static|rip|ospf|isis|bgp|pim|table|any)')
line = line.replace('" QUAGGA_IP6_PROTOCOL_MAP_STR_ZEBRA "', '(kernel|connected|static|ripng|ospf6|isis|bgp|table|any)')
line = line.replace('" QUAGGA_REDIST_STR_RIPNGD "', '(kernel|connected|static|ospf6|isis|bgp|table)')
line = line.replace('" QUAGGA_REDIST_STR_RIPD "', '(kernel|connected|static|ospf|isis|bgp|pim|table)')
line = line.replace('" QUAGGA_REDIST_STR_OSPF6D "', '(kernel|connected|static|ripng|isis|bgp|table)')
line = line.replace('" QUAGGA_REDIST_STR_ISISD "', '(kernel|connected|static|rip|ripng|ospf|ospf6|bgp|pim|table)')
line = line.replace('" LOG_FACILITIES "', '(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)')
# endswith
line = line.replace('" CMD_AS_RANGE,', ' <1-4294967295>",')
line = line.replace('" DYNAMIC_NEIGHBOR_LIMIT_RANGE,', ' <1-5000>",')
line = line.replace('" BGP_INSTANCE_CMD,', ' (view|vrf) WORD",')
line = line.replace('" BGP_INSTANCE_ALL_CMD,', ' (view|vrf) all",')
line = line.replace('" CMD_RANGE_STR(1, MULTIPATH_NUM),', '<1-255>",')
line = line.replace('" CMD_RANGE_STR(1, MAXTTL),', '<1-255>",')
line = line.replace('" BFD_CMD_DETECT_MULT_RANGE BFD_CMD_MIN_RX_RANGE BFD_CMD_MIN_TX_RANGE,', '<2-255> <50-60000> <50-60000>",')
line = line.replace('" OSPF_LSA_TYPES_CMD_STR,',
' asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as",')
line = line.replace('" BGP_UPDATE_SOURCE_REQ_STR,', ' (A.B.C.D|X:X::X:X|WORD)",')
line = line.replace('" BGP_UPDATE_SOURCE_OPT_STR,', ' {A.B.C.D|X:X::X:X|WORD}",')
line = line.replace('" QUAGGA_IP_REDIST_STR_BGPD,', ' (kernel|connected|static|rip|ospf|isis|pim|table)",')
line = line.replace('" QUAGGA_IP6_REDIST_STR_BGPD,', ' (kernel|connected|static|ripng|ospf6|isis|table)",')
line = line.replace('" QUAGGA_REDIST_STR_OSPFD,', ' (kernel|connected|static|rip|isis|bgp|pim|table)",')
line = line.replace('" VRF_CMD_STR,', ' vrf NAME",')
line = line.replace('" VRF_ALL_CMD_STR,', ' vrf all",')
line = line.replace('" QUAGGA_IP_REDIST_STR_ZEBRA,', ' (kernel|connected|static|rip|ospf|isis|bgp|pim|table)",')
line = line.replace('" QUAGGA_IP6_REDIST_STR_ZEBRA,', ' (kernel|connected|static|ripng|ospf6|isis|bgp|table)",')
line = line.replace('" QUAGGA_IP_PROTOCOL_MAP_STR_ZEBRA,', ' (kernel|connected|static|rip|ospf|isis|bgp|pim|table|any)",')
line = line.replace('" QUAGGA_IP6_PROTOCOL_MAP_STR_ZEBRA,', ' (kernel|connected|static|ripng|ospf6|isis|bgp|table|any)",')
line = line.replace('" QUAGGA_REDIST_STR_RIPNGD,', ' (kernel|connected|static|ospf6|isis|bgp|table)",')
line = line.replace('" QUAGGA_REDIST_STR_RIPD,', ' (kernel|connected|static|ospf|isis|bgp|pim|table)",')
line = line.replace('" PIM_CMD_IP_MULTICAST_ROUTING,', ' ip multicast-routing",')
line = line.replace('" PIM_CMD_IP_IGMP_QUERY_INTERVAL,', ' ip igmp query-interval",')
line = line.replace('" PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC,', ' ip igmp query-max-response-time-dsec",')
line = line.replace('" PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME,', ' ip igmp query-max-response-time",')
line = line.replace('" QUAGGA_REDIST_STR_OSPF6D,', ' (kernel|connected|static|ripng|isis|bgp|table)",')
line = line.replace('" QUAGGA_REDIST_STR_ISISD,', ' (kernel|connected|static|rip|ripng|ospf|ospf6|bgp|pim|table)",')
line = line.replace('" LOG_FACILITIES,', ' (kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)",')
# startswith
line = line.replace('LISTEN_RANGE_CMD "', '"bgp listen range (A.B.C.D/M|X:X::X:X/M) ')
line = line.replace('NO_NEIGHBOR_CMD2 "', '"no neighbor (A.B.C.D|X:X::X:X|WORD) ')
line = line.replace('NEIGHBOR_CMD2 "', '"neighbor (A.B.C.D|X:X::X:X|WORD) ')
line = line.replace('NO_NEIGHBOR_CMD "', '"no neighbor (A.B.C.D|X:X::X:X) ')
line = line.replace('NEIGHBOR_CMD "', '"neighbor (A.B.C.D|X:X::X:X) ')
line = line.replace('PIM_CMD_NO "', '"no ')
line = line.replace('PIM_CMD_IP_IGMP_QUERY_INTERVAL "', '"ip igmp query-interval ')
line = line.replace('PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME "', '"ip igmp query-max-response-time ')
line = line.replace('PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC "', '"ip igmp query-max-response-time-dsec ')
# solo
line = line.replace('NO_NEIGHBOR_CMD2,', '"no neighbor (A.B.C.D|X:X::X:X|WORD)",')
line = line.replace('NEIGHBOR_CMD2,', '"neighbor (A.B.C.D|X:X::X:X|WORD)",')
line = line.replace('NO_NEIGHBOR_CMD,', '"no neighbor (A.B.C.D|X:X::X:X)",')
line = line.replace('NEIGHBOR_CMD,', '"neighbor (A.B.C.D|X:X::X:X)",')
line = line.replace('PIM_CMD_IP_MULTICAST_ROUTING,', '"ip multicast-routing",')
if line.rstrip().endswith('" ,'):
line = line.replace('" ,', '",')
command_string = line command_string = line
''' '''

View File

@ -130,12 +130,13 @@ DEFUN (debug_zebra_packet_direct,
"Debug option set for receive packet\n" "Debug option set for receive packet\n"
"Debug option set for send packet\n") "Debug option set for send packet\n")
{ {
int idx_recv_send = 3;
zebra_debug_packet = ZEBRA_DEBUG_PACKET; zebra_debug_packet = ZEBRA_DEBUG_PACKET;
if (strncmp ("send", argv[3]->arg, strlen (argv[3]->arg)) == 0) if (strncmp ("send", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND); SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
if (strncmp ("recv", argv[3]->arg, strlen (argv[3]->arg)) == 0) if (strncmp ("recv", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV); SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
if (strncmp ("detail", argv[3]->arg, strlen (argv[3]->arg)) == 0) if (strncmp ("detail", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL); SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -150,10 +151,11 @@ DEFUN (debug_zebra_packet_detail,
"Debug option set for send packet\n" "Debug option set for send packet\n"
"Debug option set detailed information\n") "Debug option set detailed information\n")
{ {
int idx_recv_send = 3;
zebra_debug_packet = ZEBRA_DEBUG_PACKET; zebra_debug_packet = ZEBRA_DEBUG_PACKET;
if (strncmp ("send", argv[3]->arg, strlen (argv[3]->arg)) == 0) if (strncmp ("send", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND); SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
if (strncmp ("recv", argv[3]->arg, strlen (argv[3]->arg)) == 0) if (strncmp ("recv", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV); SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL); SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
return CMD_SUCCESS; return CMD_SUCCESS;
@ -180,9 +182,10 @@ DEFUN (debug_zebra_kernel_msgdump,
"Dump raw netlink messages received\n" "Dump raw netlink messages received\n"
"Dump raw netlink messages sent\n") "Dump raw netlink messages sent\n")
{ {
if (argv[4]->arg && strncmp(argv[4]->arg, "recv", strlen(argv[4]->arg)) == 0) int idx_recv_send = 4;
if (argv[idx_recv_send]->arg && strncmp(argv[idx_recv_send]->arg, "recv", strlen(argv[idx_recv_send]->arg)) == 0)
SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
if (!argv[4]->arg || strncmp(argv[4]->arg, "send", strlen(argv[4]->arg)) == 0) if (!argv[idx_recv_send]->arg || strncmp(argv[idx_recv_send]->arg, "send", strlen(argv[idx_recv_send]->arg)) == 0)
SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -267,9 +270,10 @@ DEFUN (no_debug_zebra_packet_direct,
"Debug option set for receive packet\n" "Debug option set for receive packet\n"
"Debug option set for send packet\n") "Debug option set for send packet\n")
{ {
if (strncmp ("send", argv[4]->arg, strlen (argv[4]->arg)) == 0) int idx_recv_send = 4;
if (strncmp ("send", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND); UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
if (strncmp ("recv", argv[4]->arg, strlen (argv[4]->arg)) == 0) if (strncmp ("recv", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV); UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -296,9 +300,10 @@ DEFUN (no_debug_zebra_kernel_msgdump,
"Dump raw netlink messages received\n" "Dump raw netlink messages received\n"
"Dump raw netlink messages sent\n") "Dump raw netlink messages sent\n")
{ {
if (!argv[1] || (argv[5]->arg && strncmp(argv[5]->arg, "recv", strlen(argv[5]->arg)) == 0)) int idx_recv_send = 5;
if (!argv[1] || (argv[idx_recv_send]->arg && strncmp(argv[idx_recv_send]->arg, "recv", strlen(argv[idx_recv_send]->arg)) == 0))
UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
if (!argv[5]->arg || (argv[5]->arg && strncmp(argv[5]->arg, "send", strlen(argv[5]->arg)) == 0)) if (!argv[idx_recv_send]->arg || (argv[idx_recv_send]->arg && strncmp(argv[idx_recv_send]->arg, "send", strlen(argv[idx_recv_send]->arg)) == 0))
UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -1361,19 +1361,21 @@ DEFUN (show_interface_name_vrf,
"Interface name\n" "Interface name\n"
VRF_CMD_HELP_STR) VRF_CMD_HELP_STR)
{ {
int idx_ifname = 2;
int idx_name = 4;
struct interface *ifp; struct interface *ifp;
vrf_id_t vrf_id = VRF_DEFAULT; vrf_id_t vrf_id = VRF_DEFAULT;
interface_update_stats (); interface_update_stats ();
if (argc > 1) if (argc > 1)
VRF_GET_ID (vrf_id, argv[4]->arg); VRF_GET_ID (vrf_id, argv[idx_name]->arg);
/* Specified interface print. */ /* Specified interface print. */
ifp = if_lookup_by_name_vrf (argv[2]->arg, vrf_id); ifp = if_lookup_by_name_vrf (argv[idx_ifname]->arg, vrf_id);
if (ifp == NULL) if (ifp == NULL)
{ {
vty_out (vty, "%% Can't find interface %s%s", argv[2]->arg, vty_out (vty, "%% Can't find interface %s%s", argv[idx_ifname]->arg,
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
@ -1399,6 +1401,7 @@ DEFUN (show_interface_name_vrf_all,
"Interface name\n" "Interface name\n"
VRF_ALL_CMD_HELP_STR) VRF_ALL_CMD_HELP_STR)
{ {
int idx_ifname = 2;
struct interface *ifp; struct interface *ifp;
vrf_iter_t iter; vrf_iter_t iter;
int found = 0; int found = 0;
@ -1409,7 +1412,7 @@ DEFUN (show_interface_name_vrf_all,
for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
{ {
/* Specified interface print. */ /* Specified interface print. */
ifp = if_lookup_by_name_vrf (argv[2]->arg, vrf_iter2id (iter)); ifp = if_lookup_by_name_vrf (argv[idx_ifname]->arg, vrf_iter2id (iter));
if (ifp) if (ifp)
{ {
if_dump_vty (vty, ifp); if_dump_vty (vty, ifp);
@ -1419,7 +1422,7 @@ DEFUN (show_interface_name_vrf_all,
if (!found) if (!found)
{ {
vty_out (vty, "%% Can't find interface %s%s", argv[2]->arg, VTY_NEWLINE); vty_out (vty, "%% Can't find interface %s%s", argv[idx_ifname]->arg, VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
@ -1678,11 +1681,12 @@ DEFUN (bandwidth_if,
"Set bandwidth informational parameter\n" "Set bandwidth informational parameter\n"
"Bandwidth in megabits\n") "Bandwidth in megabits\n")
{ {
int idx_number = 1;
struct interface *ifp; struct interface *ifp;
unsigned int bandwidth; unsigned int bandwidth;
ifp = (struct interface *) vty->index; ifp = (struct interface *) vty->index;
bandwidth = strtol(argv[1]->arg, NULL, 10); bandwidth = strtol(argv[idx_number]->arg, NULL, 10);
/* bandwidth range is <1-100000> */ /* bandwidth range is <1-100000> */
if (bandwidth < 1 || bandwidth > 100000) if (bandwidth < 1 || bandwidth > 100000)
@ -1844,11 +1848,12 @@ DEFUN (link_params_metric,
"Link metric for MPLS-TE purpose\n" "Link metric for MPLS-TE purpose\n"
"Metric value in decimal\n") "Metric value in decimal\n")
{ {
int idx_number = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
u_int32_t metric; u_int32_t metric;
VTY_GET_ULONG("metric", metric, argv[1]->arg); VTY_GET_ULONG("metric", metric, argv[idx_number]->arg);
/* Update TE metric if needed */ /* Update TE metric if needed */
link_param_cmd_set_uint32 (ifp, &iflp->te_metric, LP_TE, metric); link_param_cmd_set_uint32 (ifp, &iflp->te_metric, LP_TE, metric);
@ -1876,12 +1881,13 @@ DEFUN (link_params_maxbw,
"Maximum bandwidth that can be used\n" "Maximum bandwidth that can be used\n"
"Bytes/second (IEEE floating point format)\n") "Bytes/second (IEEE floating point format)\n")
{ {
int idx_bandwidth = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
float bw; float bw;
if (sscanf (argv[1]->arg, "%g", &bw) != 1) if (sscanf (argv[idx_bandwidth]->arg, "%g", &bw) != 1)
{ {
vty_out (vty, "link_params_maxbw: fscanf: %s%s", safe_strerror (errno), vty_out (vty, "link_params_maxbw: fscanf: %s%s", safe_strerror (errno),
VTY_NEWLINE); VTY_NEWLINE);
@ -1920,11 +1926,12 @@ DEFUN (link_params_max_rsv_bw,
"Maximum bandwidth that may be reserved\n" "Maximum bandwidth that may be reserved\n"
"Bytes/second (IEEE floating point format)\n") "Bytes/second (IEEE floating point format)\n")
{ {
int idx_bandwidth = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
float bw; float bw;
if (sscanf (argv[1]->arg, "%g", &bw) != 1) if (sscanf (argv[idx_bandwidth]->arg, "%g", &bw) != 1)
{ {
vty_out (vty, "link_params_max_rsv_bw: fscanf: %s%s", safe_strerror (errno), vty_out (vty, "link_params_max_rsv_bw: fscanf: %s%s", safe_strerror (errno),
VTY_NEWLINE); VTY_NEWLINE);
@ -1953,20 +1960,22 @@ DEFUN (link_params_unrsv_bw,
"Priority\n" "Priority\n"
"Bytes/second (IEEE floating point format)\n") "Bytes/second (IEEE floating point format)\n")
{ {
int idx_number = 1;
int idx_bandwidth = 2;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
int priority; int priority;
float bw; float bw;
/* We don't have to consider about range check here. */ /* We don't have to consider about range check here. */
if (sscanf (argv[1]->arg, "%d", &priority) != 1) if (sscanf (argv[idx_number]->arg, "%d", &priority) != 1)
{ {
vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno), vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno),
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
if (sscanf (argv[2]->arg, "%g", &bw) != 1) if (sscanf (argv[idx_bandwidth]->arg, "%g", &bw) != 1)
{ {
vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno), vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno),
VTY_NEWLINE); VTY_NEWLINE);
@ -1994,11 +2003,12 @@ DEFUN (link_params_admin_grp,
"Administrative group membership\n" "Administrative group membership\n"
"32-bit Hexadecimal value (e.g. 0xa1)\n") "32-bit Hexadecimal value (e.g. 0xa1)\n")
{ {
int idx_bitpattern = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
unsigned long value; unsigned long value;
if (sscanf (argv[1]->arg, "0x%lx", &value) != 1) if (sscanf (argv[idx_bitpattern]->arg, "0x%lx", &value) != 1)
{ {
vty_out (vty, "link_params_admin_grp: fscanf: %s%s", vty_out (vty, "link_params_admin_grp: fscanf: %s%s",
safe_strerror (errno), VTY_NEWLINE); safe_strerror (errno), VTY_NEWLINE);
@ -2034,19 +2044,21 @@ DEFUN (link_params_inter_as,
"Remote AS number\n" "Remote AS number\n"
"AS number in the range <1-4294967295>\n") "AS number in the range <1-4294967295>\n")
{ {
int idx_ipv4 = 1;
int idx_number = 3;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
struct in_addr addr; struct in_addr addr;
u_int32_t as; u_int32_t as;
if (!inet_aton (argv[1]->arg, &addr)) if (!inet_aton (argv[idx_ipv4]->arg, &addr))
{ {
vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE); vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
VTY_GET_ULONG("AS number", as, argv[3]->arg); VTY_GET_ULONG("AS number", as, argv[idx_number]->arg);
/* Update Remote IP and Remote AS fields if needed */ /* Update Remote IP and Remote AS fields if needed */
if (IS_PARAM_UNSET(iflp, LP_RMT_AS) if (IS_PARAM_UNSET(iflp, LP_RMT_AS)
@ -2105,6 +2117,7 @@ DEFUN (link_params_delay,
"Unidirectional Average Link Delay\n" "Unidirectional Average Link Delay\n"
"Average delay in micro-second as decimal (0...16777215)\n") "Average delay in micro-second as decimal (0...16777215)\n")
{ {
int idx_number = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
@ -2112,7 +2125,7 @@ DEFUN (link_params_delay,
u_int8_t update = 0; u_int8_t update = 0;
/* Get and Check new delay values */ /* Get and Check new delay values */
VTY_GET_ULONG("delay", delay, argv[1]->arg); VTY_GET_ULONG("delay", delay, argv[idx_number]->arg);
switch (argc) switch (argc)
{ {
case 1: case 1:
@ -2212,11 +2225,12 @@ DEFUN (link_params_delay_var,
"Unidirectional Link Delay Variation\n" "Unidirectional Link Delay Variation\n"
"delay variation in micro-second as decimal (0...16777215)\n") "delay variation in micro-second as decimal (0...16777215)\n")
{ {
int idx_number = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
u_int32_t value; u_int32_t value;
VTY_GET_ULONG("delay variation", value, argv[1]->arg); VTY_GET_ULONG("delay variation", value, argv[idx_number]->arg);
/* Update Delay Variation if needed */ /* Update Delay Variation if needed */
link_param_cmd_set_uint32 (ifp, &iflp->delay_var, LP_DELAY_VAR, value); link_param_cmd_set_uint32 (ifp, &iflp->delay_var, LP_DELAY_VAR, value);
@ -2244,11 +2258,12 @@ DEFUN (link_params_pkt_loss,
"Unidirectional Link Packet Loss\n" "Unidirectional Link Packet Loss\n"
"percentage of total traffic by 0.000003% step and less than 50.331642%\n") "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
{ {
int idx_percentage = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
float fval; float fval;
if (sscanf (argv[1]->arg, "%g", &fval) != 1) if (sscanf (argv[idx_percentage]->arg, "%g", &fval) != 1)
{ {
vty_out (vty, "link_params_pkt_loss: fscanf: %s%s", safe_strerror (errno), vty_out (vty, "link_params_pkt_loss: fscanf: %s%s", safe_strerror (errno),
VTY_NEWLINE); VTY_NEWLINE);
@ -2284,11 +2299,12 @@ DEFUN (link_params_res_bw,
"Unidirectional Residual Bandwidth\n" "Unidirectional Residual Bandwidth\n"
"Bytes/second (IEEE floating point format)\n") "Bytes/second (IEEE floating point format)\n")
{ {
int idx_bandwidth = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
float bw; float bw;
if (sscanf (argv[1]->arg, "%g", &bw) != 1) if (sscanf (argv[idx_bandwidth]->arg, "%g", &bw) != 1)
{ {
vty_out (vty, "link_params_res_bw: fscanf: %s%s", safe_strerror (errno), vty_out (vty, "link_params_res_bw: fscanf: %s%s", safe_strerror (errno),
VTY_NEWLINE); VTY_NEWLINE);
@ -2330,11 +2346,12 @@ DEFUN (link_params_ava_bw,
"Unidirectional Available Bandwidth\n" "Unidirectional Available Bandwidth\n"
"Bytes/second (IEEE floating point format)\n") "Bytes/second (IEEE floating point format)\n")
{ {
int idx_bandwidth = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
float bw; float bw;
if (sscanf (argv[1]->arg, "%g", &bw) != 1) if (sscanf (argv[idx_bandwidth]->arg, "%g", &bw) != 1)
{ {
vty_out (vty, "link_params_ava_bw: fscanf: %s%s", safe_strerror (errno), vty_out (vty, "link_params_ava_bw: fscanf: %s%s", safe_strerror (errno),
VTY_NEWLINE); VTY_NEWLINE);
@ -2376,11 +2393,12 @@ DEFUN (link_params_use_bw,
"Unidirectional Utilised Bandwidth\n" "Unidirectional Utilised Bandwidth\n"
"Bytes/second (IEEE floating point format)\n") "Bytes/second (IEEE floating point format)\n")
{ {
int idx_bandwidth = 1;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct if_link_params *iflp = if_link_params_get (ifp); struct if_link_params *iflp = if_link_params_get (ifp);
float bw; float bw;
if (sscanf (argv[1]->arg, "%g", &bw) != 1) if (sscanf (argv[idx_bandwidth]->arg, "%g", &bw) != 1)
{ {
vty_out (vty, "link_params_use_bw: fscanf: %s%s", safe_strerror (errno), vty_out (vty, "link_params_use_bw: fscanf: %s%s", safe_strerror (errno),
VTY_NEWLINE); VTY_NEWLINE);
@ -2564,7 +2582,8 @@ DEFUN (ip_address,
"Set the IP address of an interface\n" "Set the IP address of an interface\n"
"IP address (e.g. 10.0.0.1/8)\n") "IP address (e.g. 10.0.0.1/8)\n")
{ {
return ip_address_install (vty, vty->index, argv[2]->arg, NULL, NULL); int idx_ipv4_prefixlen = 2;
return ip_address_install (vty, vty->index, argv[idx_ipv4_prefixlen]->arg, NULL, NULL);
} }
DEFUN (no_ip_address, DEFUN (no_ip_address,
@ -2575,7 +2594,8 @@ DEFUN (no_ip_address,
"Set the IP address of an interface\n" "Set the IP address of an interface\n"
"IP Address (e.g. 10.0.0.1/8)") "IP Address (e.g. 10.0.0.1/8)")
{ {
return ip_address_uninstall (vty, vty->index, argv[3]->arg, NULL, NULL); int idx_ipv4_prefixlen = 3;
return ip_address_uninstall (vty, vty->index, argv[idx_ipv4_prefixlen]->arg, NULL, NULL);
} }
@ -2589,7 +2609,9 @@ DEFUN (ip_address_label,
"Label of this address\n" "Label of this address\n"
"Label\n") "Label\n")
{ {
return ip_address_install (vty, vty->index, argv[2]->arg, NULL, argv[4]->arg); int idx_ipv4_prefixlen = 2;
int idx_line = 4;
return ip_address_install (vty, vty->index, argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_line]->arg);
} }
DEFUN (no_ip_address_label, DEFUN (no_ip_address_label,
@ -2602,7 +2624,9 @@ DEFUN (no_ip_address_label,
"Label of this address\n" "Label of this address\n"
"Label\n") "Label\n")
{ {
return ip_address_uninstall (vty, vty->index, argv[3]->arg, NULL, argv[5]->arg); int idx_ipv4_prefixlen = 3;
int idx_line = 5;
return ip_address_uninstall (vty, vty->index, argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_line]->arg);
} }
#endif /* HAVE_NETLINK */ #endif /* HAVE_NETLINK */
@ -2765,7 +2789,8 @@ DEFUN (ipv6_address,
"Set the IP address of an interface\n" "Set the IP address of an interface\n"
"IPv6 address (e.g. 3ffe:506::1/48)\n") "IPv6 address (e.g. 3ffe:506::1/48)\n")
{ {
return ipv6_address_install (vty, vty->index, argv[2]->arg, NULL, NULL, 0); int idx_ipv6_prefixlen = 2;
return ipv6_address_install (vty, vty->index, argv[idx_ipv6_prefixlen]->arg, NULL, NULL, 0);
} }
DEFUN (no_ipv6_address, DEFUN (no_ipv6_address,
@ -2776,7 +2801,8 @@ DEFUN (no_ipv6_address,
"Set the IP address of an interface\n" "Set the IP address of an interface\n"
"IPv6 address (e.g. 3ffe:506::1/48)\n") "IPv6 address (e.g. 3ffe:506::1/48)\n")
{ {
return ipv6_address_uninstall (vty, vty->index, argv[3]->arg, NULL, NULL, 0); int idx_ipv6_prefixlen = 3;
return ipv6_address_uninstall (vty, vty->index, argv[idx_ipv6_prefixlen]->arg, NULL, NULL, 0);
} }
#endif /* HAVE_IPV6 */ #endif /* HAVE_IPV6 */

View File

@ -469,6 +469,7 @@ DEFUN (ip_irdp_holdtime,
"Set holdtime value\n" "Set holdtime value\n"
"Holdtime value in seconds. Default is 1800 seconds\n") "Holdtime value in seconds. Default is 1800 seconds\n")
{ {
int idx_number = 3;
struct interface *ifp; struct interface *ifp;
struct zebra_if *zi; struct zebra_if *zi;
struct irdp_interface *irdp; struct irdp_interface *irdp;
@ -480,7 +481,7 @@ DEFUN (ip_irdp_holdtime,
zi=ifp->info; zi=ifp->info;
irdp=&zi->irdp; irdp=&zi->irdp;
irdp->Lifetime = atoi(argv[3]->arg); irdp->Lifetime = atoi(argv[idx_number]->arg);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -492,6 +493,7 @@ DEFUN (ip_irdp_minadvertinterval,
"Set minimum time between advertisement\n" "Set minimum time between advertisement\n"
"Minimum advertisement interval in seconds\n") "Minimum advertisement interval in seconds\n")
{ {
int idx_number = 3;
struct interface *ifp; struct interface *ifp;
struct zebra_if *zi; struct zebra_if *zi;
struct irdp_interface *irdp; struct irdp_interface *irdp;
@ -503,8 +505,8 @@ DEFUN (ip_irdp_minadvertinterval,
zi=ifp->info; zi=ifp->info;
irdp=&zi->irdp; irdp=&zi->irdp;
if( (unsigned) atoi(argv[3]->arg) <= irdp->MaxAdvertInterval) { if( (unsigned) atoi(argv[idx_number]->arg) <= irdp->MaxAdvertInterval) {
irdp->MinAdvertInterval = atoi(argv[3]->arg); irdp->MinAdvertInterval = atoi(argv[idx_number]->arg);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -525,6 +527,7 @@ DEFUN (ip_irdp_maxadvertinterval,
"Set maximum time between advertisement\n" "Set maximum time between advertisement\n"
"Maximum advertisement interval in seconds\n") "Maximum advertisement interval in seconds\n")
{ {
int idx_number = 3;
struct interface *ifp; struct interface *ifp;
struct zebra_if *zi; struct zebra_if *zi;
struct irdp_interface *irdp; struct irdp_interface *irdp;
@ -537,8 +540,8 @@ DEFUN (ip_irdp_maxadvertinterval,
irdp=&zi->irdp; irdp=&zi->irdp;
if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[3]->arg) ) { if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[idx_number]->arg) ) {
irdp->MaxAdvertInterval = atoi(argv[3]->arg); irdp->MaxAdvertInterval = atoi(argv[idx_number]->arg);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -564,6 +567,7 @@ DEFUN (ip_irdp_preference,
"Set default preference level for this interface\n" "Set default preference level for this interface\n"
"Preference level\n") "Preference level\n")
{ {
int idx_number = 3;
struct interface *ifp; struct interface *ifp;
struct zebra_if *zi; struct zebra_if *zi;
struct irdp_interface *irdp; struct irdp_interface *irdp;
@ -575,7 +579,7 @@ DEFUN (ip_irdp_preference,
zi=ifp->info; zi=ifp->info;
irdp=&zi->irdp; irdp=&zi->irdp;
irdp->Preference = atoi(argv[3]->arg); irdp->Preference = atoi(argv[idx_number]->arg);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -588,6 +592,8 @@ DEFUN (ip_irdp_address_preference,
"Set IRDP address for advertise\n" "Set IRDP address for advertise\n"
"Preference level\n") "Preference level\n")
{ {
int idx_ipv4 = 3;
int idx_number = 5;
struct listnode *node; struct listnode *node;
struct in_addr ip; struct in_addr ip;
int pref; int pref;
@ -605,10 +611,10 @@ DEFUN (ip_irdp_address_preference,
zi=ifp->info; zi=ifp->info;
irdp=&zi->irdp; irdp=&zi->irdp;
ret = inet_aton(argv[3]->arg, &ip); ret = inet_aton(argv[idx_ipv4]->arg, &ip);
if(!ret) return CMD_WARNING; if(!ret) return CMD_WARNING;
pref = atoi(argv[5]->arg); pref = atoi(argv[idx_number]->arg);
for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv)) for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
if(adv->ip.s_addr == ip.s_addr) if(adv->ip.s_addr == ip.s_addr)
@ -633,6 +639,7 @@ DEFUN (no_ip_irdp_address_preference,
"Select IRDP address\n" "Select IRDP address\n"
"Old preference level\n") "Old preference level\n")
{ {
int idx_ipv4 = 4;
struct listnode *node, *nnode; struct listnode *node, *nnode;
struct in_addr ip; struct in_addr ip;
int ret; int ret;
@ -649,7 +656,7 @@ DEFUN (no_ip_irdp_address_preference,
zi=ifp->info; zi=ifp->info;
irdp=&zi->irdp; irdp=&zi->irdp;
ret = inet_aton(argv[4]->arg, &ip); ret = inet_aton(argv[idx_ipv4]->arg, &ip);
if (!ret) if (!ret)
return CMD_WARNING; return CMD_WARNING;

View File

@ -228,10 +228,11 @@ DEFUN (router_id,
"Manually set the router-id\n" "Manually set the router-id\n"
"IP address to use for router-id\n") "IP address to use for router-id\n")
{ {
int idx_ipv4 = 1;
struct prefix rid; struct prefix rid;
vrf_id_t vrf_id = VRF_DEFAULT; vrf_id_t vrf_id = VRF_DEFAULT;
rid.u.prefix4.s_addr = inet_addr (argv[1]->arg); rid.u.prefix4.s_addr = inet_addr (argv[idx_ipv4]->arg);
if (!rid.u.prefix4.s_addr) if (!rid.u.prefix4.s_addr)
return CMD_WARNING; return CMD_WARNING;

View File

@ -923,6 +923,7 @@ DEFUN (ipv6_nd_ra_interval_msec,
"Router Advertisement interval\n" "Router Advertisement interval\n"
"Router Advertisement interval in milliseconds\n") "Router Advertisement interval in milliseconds\n")
{ {
int idx_number = 4;
unsigned interval; unsigned interval;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct zebra_if *zif = ifp->info; struct zebra_if *zif = ifp->info;
@ -930,7 +931,7 @@ DEFUN (ipv6_nd_ra_interval_msec,
struct zebra_ns *zns; struct zebra_ns *zns;
zns = zvrf->zns; zns = zvrf->zns;
VTY_GET_INTEGER_RANGE ("router advertisement interval", interval, argv[4]->arg, 70, 1800000); VTY_GET_INTEGER_RANGE ("router advertisement interval", interval, argv[idx_number]->arg, 70, 1800000);
if ((zif->rtadv.AdvDefaultLifetime != -1 && interval > (unsigned)zif->rtadv.AdvDefaultLifetime * 1000)) if ((zif->rtadv.AdvDefaultLifetime != -1 && interval > (unsigned)zif->rtadv.AdvDefaultLifetime * 1000))
{ {
vty_out (vty, "This ra-interval would conflict with configured ra-lifetime!%s", VTY_NEWLINE); vty_out (vty, "This ra-interval would conflict with configured ra-lifetime!%s", VTY_NEWLINE);
@ -958,6 +959,7 @@ DEFUN (ipv6_nd_ra_interval,
"Router Advertisement interval\n" "Router Advertisement interval\n"
"Router Advertisement interval in seconds\n") "Router Advertisement interval in seconds\n")
{ {
int idx_number = 3;
unsigned interval; unsigned interval;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct zebra_if *zif = ifp->info; struct zebra_if *zif = ifp->info;
@ -965,7 +967,7 @@ DEFUN (ipv6_nd_ra_interval,
struct zebra_ns *zns; struct zebra_ns *zns;
zns = zvrf->zns; zns = zvrf->zns;
VTY_GET_INTEGER_RANGE ("router advertisement interval", interval, argv[3]->arg, 1, 1800); VTY_GET_INTEGER_RANGE ("router advertisement interval", interval, argv[idx_number]->arg, 1, 1800);
if ((zif->rtadv.AdvDefaultLifetime != -1 && interval > (unsigned)zif->rtadv.AdvDefaultLifetime)) if ((zif->rtadv.AdvDefaultLifetime != -1 && interval > (unsigned)zif->rtadv.AdvDefaultLifetime))
{ {
vty_out (vty, "This ra-interval would conflict with configured ra-lifetime!%s", VTY_NEWLINE); vty_out (vty, "This ra-interval would conflict with configured ra-lifetime!%s", VTY_NEWLINE);
@ -1039,6 +1041,7 @@ DEFUN (ipv6_nd_ra_lifetime,
"Router lifetime\n" "Router lifetime\n"
"Router lifetime in seconds (0 stands for a non-default gw)\n") "Router lifetime in seconds (0 stands for a non-default gw)\n")
{ {
int idx_number = 3;
int lifetime; int lifetime;
struct interface *ifp; struct interface *ifp;
struct zebra_if *zif; struct zebra_if *zif;
@ -1046,7 +1049,7 @@ DEFUN (ipv6_nd_ra_lifetime,
ifp = (struct interface *) vty->index; ifp = (struct interface *) vty->index;
zif = ifp->info; zif = ifp->info;
VTY_GET_INTEGER_RANGE ("router lifetime", lifetime, argv[3]->arg, 0, 9000); VTY_GET_INTEGER_RANGE ("router lifetime", lifetime, argv[idx_number]->arg, 0, 9000);
/* The value to be placed in the Router Lifetime field /* The value to be placed in the Router Lifetime field
* of Router Advertisements sent from the interface, * of Router Advertisements sent from the interface,
@ -1101,9 +1104,10 @@ DEFUN (ipv6_nd_reachable_time,
"Reachable time\n" "Reachable time\n"
"Reachable time in milliseconds\n") "Reachable time in milliseconds\n")
{ {
int idx_number = 3;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct zebra_if *zif = ifp->info; struct zebra_if *zif = ifp->info;
VTY_GET_INTEGER_RANGE ("reachable time", zif->rtadv.AdvReachableTime, argv[3]->arg, 1, RTADV_MAX_REACHABLE_TIME); VTY_GET_INTEGER_RANGE ("reachable time", zif->rtadv.AdvReachableTime, argv[idx_number]->arg, 1, RTADV_MAX_REACHABLE_TIME);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -1145,9 +1149,10 @@ DEFUN (ipv6_nd_homeagent_preference,
"Home Agent preference\n" "Home Agent preference\n"
"preference value (default is 0, least preferred)\n") "preference value (default is 0, least preferred)\n")
{ {
int idx_number = 3;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct zebra_if *zif = ifp->info; struct zebra_if *zif = ifp->info;
VTY_GET_INTEGER_RANGE ("home agent preference", zif->rtadv.HomeAgentPreference, argv[3]->arg, 0, 65535); VTY_GET_INTEGER_RANGE ("home agent preference", zif->rtadv.HomeAgentPreference, argv[idx_number]->arg, 0, 65535);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -1189,9 +1194,10 @@ DEFUN (ipv6_nd_homeagent_lifetime,
"Home Agent lifetime\n" "Home Agent lifetime\n"
"Home Agent lifetime in seconds (0 to track ra-lifetime)\n") "Home Agent lifetime in seconds (0 to track ra-lifetime)\n")
{ {
int idx_number = 3;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct zebra_if *zif = ifp->info; struct zebra_if *zif = ifp->info;
VTY_GET_INTEGER_RANGE ("home agent lifetime", zif->rtadv.HomeAgentLifetime, argv[3]->arg, 0, RTADV_MAX_HALIFETIME); VTY_GET_INTEGER_RANGE ("home agent lifetime", zif->rtadv.HomeAgentLifetime, argv[idx_number]->arg, 0, RTADV_MAX_HALIFETIME);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -1508,7 +1514,7 @@ DEFUN (no_ipv6_nd_other_config_flag,
*/ */
DEFUN (ipv6_nd_prefix, DEFUN (ipv6_nd_prefix,
ipv6_nd_prefix_cmd, ipv6_nd_prefix_cmd,
"ipv6 nd prefix X:X::X:X/M <(0-4294967295)|infinite> <(0-4294967295)|infinite> <off-link|> <no-autoconfig|> <router-address|>", "ipv6 nd prefix X:X::X:X/M <(0-4294967295)|infinite> <(0-4294967295)|infinite> <off-link> <no-autoconfig> <router-address>",
"Interface IPv6 config commands\n" "Interface IPv6 config commands\n"
"Neighbor discovery\n" "Neighbor discovery\n"
"Prefix information\n" "Prefix information\n"
@ -1521,6 +1527,9 @@ DEFUN (ipv6_nd_prefix,
"Do not use prefix for autoconfiguration\n" "Do not use prefix for autoconfiguration\n"
"Set Router Address flag\n") "Set Router Address flag\n")
{ {
int idx_ipv6_prefixlen = 3;
int idx_number_infinite = 4;
int idx_number_infinite_2 = 5;
int i; int i;
int ret; int ret;
int cursor = 1; int cursor = 1;
@ -1531,7 +1540,7 @@ DEFUN (ipv6_nd_prefix,
ifp = (struct interface *) vty->index; ifp = (struct interface *) vty->index;
zebra_if = ifp->info; zebra_if = ifp->info;
ret = str2prefix_ipv6 (argv[3]->arg, &rp.prefix); ret = str2prefix_ipv6 (argv[idx_ipv6_prefixlen]->arg, &rp.prefix);
if (!ret) if (!ret)
{ {
vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE); vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
@ -1546,19 +1555,19 @@ DEFUN (ipv6_nd_prefix,
if (argc > 1) if (argc > 1)
{ {
if ((isdigit((unsigned char)argv[4]->arg[0])) if ((isdigit((unsigned char)argv[idx_number_infinite]->arg[0]))
|| strncmp (argv[4]->arg, "i", 1) == 0) || strncmp (argv[idx_number_infinite]->arg, "i", 1) == 0)
{ {
if ( strncmp (argv[4]->arg, "i", 1) == 0) if ( strncmp (argv[idx_number_infinite]->arg, "i", 1) == 0)
rp.AdvValidLifetime = UINT32_MAX; rp.AdvValidLifetime = UINT32_MAX;
else else
rp.AdvValidLifetime = (u_int32_t) strtoll (argv[4]->arg, rp.AdvValidLifetime = (u_int32_t) strtoll (argv[idx_number_infinite]->arg,
(char **)NULL, 10); (char **)NULL, 10);
if ( strncmp (argv[5]->arg, "i", 1) == 0) if ( strncmp (argv[idx_number_infinite_2]->arg, "i", 1) == 0)
rp.AdvPreferredLifetime = UINT32_MAX; rp.AdvPreferredLifetime = UINT32_MAX;
else else
rp.AdvPreferredLifetime = (u_int32_t) strtoll (argv[5]->arg, rp.AdvPreferredLifetime = (u_int32_t) strtoll (argv[idx_number_infinite_2]->arg,
(char **)NULL, 10); (char **)NULL, 10);
if (rp.AdvPreferredLifetime > rp.AdvValidLifetime) if (rp.AdvPreferredLifetime > rp.AdvValidLifetime)
@ -1790,6 +1799,7 @@ DEFUN (ipv6_nd_router_preference,
"Low default router preference\n" "Low default router preference\n"
"Medium default router preference (default)\n") "Medium default router preference (default)\n")
{ {
int idx_high_medium_low = 3;
struct interface *ifp; struct interface *ifp;
struct zebra_if *zif; struct zebra_if *zif;
int i = 0; int i = 0;
@ -1799,7 +1809,7 @@ DEFUN (ipv6_nd_router_preference,
while (0 != rtadv_pref_strs[i]) while (0 != rtadv_pref_strs[i])
{ {
if (strncmp (argv[3]->arg, rtadv_pref_strs[i], 1) == 0) if (strncmp (argv[idx_high_medium_low]->arg, rtadv_pref_strs[i], 1) == 0)
{ {
zif->rtadv.DefaultPreference = i; zif->rtadv.DefaultPreference = i;
return CMD_SUCCESS; return CMD_SUCCESS;
@ -1850,9 +1860,10 @@ DEFUN (ipv6_nd_mtu,
"Advertised MTU\n" "Advertised MTU\n"
"MTU in bytes\n") "MTU in bytes\n")
{ {
int idx_number = 3;
struct interface *ifp = (struct interface *) vty->index; struct interface *ifp = (struct interface *) vty->index;
struct zebra_if *zif = ifp->info; struct zebra_if *zif = ifp->info;
VTY_GET_INTEGER_RANGE ("MTU", zif->rtadv.AdvLinkMTU, argv[3]->arg, 1, 65535); VTY_GET_INTEGER_RANGE ("MTU", zif->rtadv.AdvLinkMTU, argv[idx_number]->arg, 1, 65535);
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -124,6 +124,7 @@ DEFUN (test_interface_state,
"up\n" "up\n"
"down\n") "down\n")
{ {
int idx_up_down = 1;
struct interface *ifp; struct interface *ifp;
if (argc < 1) if (argc < 1)
return CMD_WARNING; return CMD_WARNING;
@ -136,7 +137,7 @@ DEFUN (test_interface_state,
ifp->flags = IFF_BROADCAST|IFF_MULTICAST; ifp->flags = IFF_BROADCAST|IFF_MULTICAST;
} }
switch (argv[1]->arg[0]) switch (argv[idx_up_down]->arg[0])
{ {
case 'u': case 'u':
SET_FLAG (ifp->flags, IFF_UP); SET_FLAG (ifp->flags, IFF_UP);

View File

@ -301,7 +301,8 @@ DEFUN (match_interface,
"match first hop interface of route\n" "match first hop interface of route\n"
"Interface name\n") "Interface name\n")
{ {
return zebra_route_match_add (vty, vty->index, "interface", argv[2]->arg, int idx_word = 2;
return zebra_route_match_add (vty, vty->index, "interface", argv[idx_word]->arg,
RMAP_EVENT_MATCH_ADDED); RMAP_EVENT_MATCH_ADDED);
} }
@ -335,7 +336,8 @@ DEFUN (match_tag,
"Match tag of route\n" "Match tag of route\n"
"Tag value\n") "Tag value\n")
{ {
return zebra_route_match_add (vty, vty->index, "tag", argv[2]->arg, int idx_number = 2;
return zebra_route_match_add (vty, vty->index, "tag", argv[idx_number]->arg,
RMAP_EVENT_MATCH_ADDED); RMAP_EVENT_MATCH_ADDED);
} }
@ -373,7 +375,8 @@ DEFUN (match_ip_next_hop,
"IP access-list number (expanded range)\n" "IP access-list number (expanded range)\n"
"IP Access-list name\n") "IP Access-list name\n")
{ {
return zebra_route_match_add (vty, vty->index, "ip next-hop", argv[3]->arg, RMAP_EVENT_FILTER_ADDED); int idx_acl = 3;
return zebra_route_match_add (vty, vty->index, "ip next-hop", argv[idx_acl]->arg, RMAP_EVENT_FILTER_ADDED);
} }
/* /*
@ -414,8 +417,9 @@ DEFUN (match_ip_next_hop_prefix_list,
"Match entries of prefix-lists\n" "Match entries of prefix-lists\n"
"IP prefix-list name\n") "IP prefix-list name\n")
{ {
int idx_word = 4;
return zebra_route_match_add (vty, vty->index, "ip next-hop prefix-list", return zebra_route_match_add (vty, vty->index, "ip next-hop prefix-list",
argv[4]->arg, RMAP_EVENT_PLIST_ADDED); argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED);
} }
/* /*
@ -460,7 +464,8 @@ DEFUN (match_ip_address,
"IP Access-list name\n") "IP Access-list name\n")
{ {
return zebra_route_match_add (vty, vty->index, "ip address", argv[3]->arg, int idx_acl = 3;
return zebra_route_match_add (vty, vty->index, "ip address", argv[idx_acl]->arg,
RMAP_EVENT_FILTER_ADDED); RMAP_EVENT_FILTER_ADDED);
} }
@ -502,8 +507,9 @@ DEFUN (match_ip_address_prefix_list,
"Match entries of prefix-lists\n" "Match entries of prefix-lists\n"
"IP prefix-list name\n") "IP prefix-list name\n")
{ {
int idx_word = 4;
return zebra_route_match_add (vty, vty->index, "ip address prefix-list", return zebra_route_match_add (vty, vty->index, "ip address prefix-list",
argv[4]->arg, RMAP_EVENT_PLIST_ADDED); argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED);
} }
/* /*
@ -627,17 +633,18 @@ DEFUN (match_source_protocol,
MATCH_STR MATCH_STR
"Match protocol via which the route was learnt\n") "Match protocol via which the route was learnt\n")
{ {
int idx_protocol = 2;
int i; int i;
i = proto_name2num(argv[2]->arg); i = proto_name2num(argv[idx_protocol]->arg);
if (i < 0) if (i < 0)
{ {
vty_out (vty, "invalid protocol name \"%s\"%s", argv[2]->arg ? argv[2]->arg : "", vty_out (vty, "invalid protocol name \"%s\"%s", argv[idx_protocol]->arg ? argv[idx_protocol]->arg : "",
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
return zebra_route_match_add (vty, vty->index, "source-protocol", return zebra_route_match_add (vty, vty->index, "source-protocol",
argv[2]->arg, RMAP_EVENT_MATCH_ADDED); argv[idx_protocol]->arg, RMAP_EVENT_MATCH_ADDED);
} }
DEFUN (no_match_source_protocol, DEFUN (no_match_source_protocol,
@ -647,20 +654,21 @@ DEFUN (no_match_source_protocol,
MATCH_STR MATCH_STR
"No match protocol via which the route was learnt\n") "No match protocol via which the route was learnt\n")
{ {
int idx_protocol = 3;
int i; int i;
if (argc >= 1) if (argc >= 1)
{ {
i = proto_name2num(argv[3]->arg); i = proto_name2num(argv[idx_protocol]->arg);
if (i < 0) if (i < 0)
{ {
vty_out (vty, "invalid protocol name \"%s\"%s", argv[3]->arg ? argv[3]->arg : "", vty_out (vty, "invalid protocol name \"%s\"%s", argv[idx_protocol]->arg ? argv[idx_protocol]->arg : "",
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
} }
return zebra_route_match_delete (vty, vty->index, return zebra_route_match_delete (vty, vty->index,
"source-protocol", argv[3]->arg ? argv[3]->arg : NULL, "source-protocol", argv[idx_protocol]->arg ? argv[idx_protocol]->arg : NULL,
RMAP_EVENT_MATCH_DELETED); RMAP_EVENT_MATCH_DELETED);
} }
@ -673,15 +681,16 @@ DEFUN (set_src,
"src address for route\n" "src address for route\n"
"src address\n") "src address\n")
{ {
int idx_ip = 2;
union g_addr src; union g_addr src;
struct interface *pif = NULL; struct interface *pif = NULL;
int family; int family;
struct prefix p; struct prefix p;
vrf_iter_t iter; vrf_iter_t iter;
if (inet_pton(AF_INET, argv[2]->arg, &src.ipv4) != 1) if (inet_pton(AF_INET, argv[idx_ip]->arg, &src.ipv4) != 1)
{ {
if (inet_pton(AF_INET6, argv[2]->arg, &src.ipv6) != 1) if (inet_pton(AF_INET6, argv[idx_ip]->arg, &src.ipv6) != 1)
{ {
vty_out (vty, "%% not a valid IPv4/v6 address%s", VTY_NEWLINE); vty_out (vty, "%% not a valid IPv4/v6 address%s", VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
@ -722,7 +731,7 @@ DEFUN (set_src,
vty_out (vty, "%% not a local address%s", VTY_NEWLINE); vty_out (vty, "%% not a local address%s", VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
return zebra_route_set_add (vty, vty->index, "src", argv[2]->arg); return zebra_route_set_add (vty, vty->index, "src", argv[idx_ip]->arg);
} }
DEFUN (no_set_src, DEFUN (no_set_src,
@ -732,10 +741,11 @@ DEFUN (no_set_src,
SET_STR SET_STR
"Source address for route\n") "Source address for route\n")
{ {
int idx_ip = 3;
if (argc == 0) if (argc == 0)
return zebra_route_set_delete (vty, vty->index, "src", NULL); return zebra_route_set_delete (vty, vty->index, "src", NULL);
return zebra_route_set_delete (vty, vty->index, "src", argv[3]->arg); return zebra_route_set_delete (vty, vty->index, "src", argv[idx_ip]->arg);
} }
DEFUN (zebra_route_map_timer, DEFUN (zebra_route_map_timer,
@ -744,9 +754,10 @@ DEFUN (zebra_route_map_timer,
"Time to wait before route-map updates are processed\n" "Time to wait before route-map updates are processed\n"
"0 means event-driven updates are disabled\n") "0 means event-driven updates are disabled\n")
{ {
int idx_number = 3;
u_int32_t rmap_delay_timer; u_int32_t rmap_delay_timer;
VTY_GET_INTEGER_RANGE ("delay-timer", rmap_delay_timer, argv[3]->arg, 0, 600); VTY_GET_INTEGER_RANGE ("delay-timer", rmap_delay_timer, argv[idx_number]->arg, 0, 600);
zebra_route_map_set_delay_timer(rmap_delay_timer); zebra_route_map_set_delay_timer(rmap_delay_timer);
return (CMD_SUCCESS); return (CMD_SUCCESS);
@ -782,15 +793,16 @@ DEFUN (ip_protocol,
QUAGGA_IP_PROTOCOL_MAP_HELP_STR_ZEBRA QUAGGA_IP_PROTOCOL_MAP_HELP_STR_ZEBRA
"Route map name\n") "Route map name\n")
{ {
int idx_protocol = 2;
int i; int i;
if (strcasecmp(argv[2]->arg, "any") == 0) if (strcasecmp(argv[idx_protocol]->arg, "any") == 0)
i = ZEBRA_ROUTE_MAX; i = ZEBRA_ROUTE_MAX;
else else
i = proto_name2num(argv[2]->arg); i = proto_name2num(argv[idx_protocol]->arg);
if (i < 0) if (i < 0)
{ {
vty_out (vty, "invalid protocol name \"%s\"%s", argv[2]->arg ? argv[2]->arg : "", vty_out (vty, "invalid protocol name \"%s\"%s", argv[idx_protocol]->arg ? argv[idx_protocol]->arg : "",
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
@ -805,7 +817,7 @@ DEFUN (ip_protocol,
if (IS_ZEBRA_DEBUG_RIB_DETAILED) if (IS_ZEBRA_DEBUG_RIB_DETAILED)
zlog_debug ("%u: IPv4 Routemap config for protocol %s, scheduling RIB processing", zlog_debug ("%u: IPv4 Routemap config for protocol %s, scheduling RIB processing",
VRF_DEFAULT, argv[2]->arg); VRF_DEFAULT, argv[idx_protocol]->arg);
rib_update(VRF_DEFAULT, RIB_UPDATE_RMAP_CHANGE); rib_update(VRF_DEFAULT, RIB_UPDATE_RMAP_CHANGE);
return CMD_SUCCESS; return CMD_SUCCESS;
@ -897,15 +909,16 @@ DEFUN (ipv6_protocol,
QUAGGA_IP6_PROTOCOL_MAP_HELP_STR_ZEBRA QUAGGA_IP6_PROTOCOL_MAP_HELP_STR_ZEBRA
"Route map name\n") "Route map name\n")
{ {
int idx_protocol = 2;
int i; int i;
if (strcasecmp(argv[2]->arg, "any") == 0) if (strcasecmp(argv[idx_protocol]->arg, "any") == 0)
i = ZEBRA_ROUTE_MAX; i = ZEBRA_ROUTE_MAX;
else else
i = proto_name2num(argv[2]->arg); i = proto_name2num(argv[idx_protocol]->arg);
if (i < 0) if (i < 0)
{ {
vty_out (vty, "invalid protocol name \"%s\"%s", argv[2]->arg ? argv[2]->arg : "", vty_out (vty, "invalid protocol name \"%s\"%s", argv[idx_protocol]->arg ? argv[idx_protocol]->arg : "",
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
@ -920,7 +933,7 @@ DEFUN (ipv6_protocol,
if (IS_ZEBRA_DEBUG_RIB_DETAILED) if (IS_ZEBRA_DEBUG_RIB_DETAILED)
zlog_debug ("%u: IPv6 Routemap config for protocol %s, scheduling RIB processing", zlog_debug ("%u: IPv6 Routemap config for protocol %s, scheduling RIB processing",
VRF_DEFAULT, argv[2]->arg); VRF_DEFAULT, argv[idx_protocol]->arg);
rib_update(VRF_DEFAULT, RIB_UPDATE_RMAP_CHANGE); rib_update(VRF_DEFAULT, RIB_UPDATE_RMAP_CHANGE);
return CMD_SUCCESS; return CMD_SUCCESS;
@ -1013,15 +1026,16 @@ DEFUN (ip_protocol_nht_rmap,
QUAGGA_IP_PROTOCOL_MAP_HELP_STR_ZEBRA QUAGGA_IP_PROTOCOL_MAP_HELP_STR_ZEBRA
"Route map name\n") "Route map name\n")
{ {
int idx_protocol = 2;
int i; int i;
if (strcasecmp(argv[2]->arg, "any") == 0) if (strcasecmp(argv[idx_protocol]->arg, "any") == 0)
i = ZEBRA_ROUTE_MAX; i = ZEBRA_ROUTE_MAX;
else else
i = proto_name2num(argv[2]->arg); i = proto_name2num(argv[idx_protocol]->arg);
if (i < 0) if (i < 0)
{ {
vty_out (vty, "invalid protocol name \"%s\"%s", argv[2]->arg ? argv[2]->arg : "", vty_out (vty, "invalid protocol name \"%s\"%s", argv[idx_protocol]->arg ? argv[idx_protocol]->arg : "",
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }
@ -1119,15 +1133,16 @@ DEFUN (ipv6_protocol_nht_rmap,
QUAGGA_IP6_PROTOCOL_MAP_HELP_STR_ZEBRA QUAGGA_IP6_PROTOCOL_MAP_HELP_STR_ZEBRA
"Route map name\n") "Route map name\n")
{ {
int idx_protocol = 2;
int i; int i;
if (strcasecmp(argv[2]->arg, "any") == 0) if (strcasecmp(argv[idx_protocol]->arg, "any") == 0)
i = ZEBRA_ROUTE_MAX; i = ZEBRA_ROUTE_MAX;
else else
i = proto_name2num(argv[2]->arg); i = proto_name2num(argv[idx_protocol]->arg);
if (i < 0) if (i < 0)
{ {
vty_out (vty, "invalid protocol name \"%s\"%s", argv[2]->arg ? argv[2]->arg : "", vty_out (vty, "invalid protocol name \"%s\"%s", argv[idx_protocol]->arg ? argv[idx_protocol]->arg : "",
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
} }

File diff suppressed because it is too large Load Diff