components/zsh/Completion/Solaris/Command/_ipadm
changeset 429 02007d525e89
child 837 3496f33edfbb
equal deleted inserted replaced
428:c1840af5fbf5 429:02007d525e89
       
     1 #compdef ipadm
       
     2 # Synced with the Nevada build 171 man page
       
     3 
       
     4 _ipadm_ifs() {
       
     5 	local -a extra
       
     6 
       
     7 	zparseopts -D -E -a extra /+:
       
     8 
       
     9 	compadd "$@" - $(ipadm show-if -p -o ifname) $extra[2,-1]
       
    10 }
       
    11 
       
    12 _ipadm_enabled_ifs() {
       
    13 	# Interfaces not marked "disabled"
       
    14 	compadd "$@" - "${(@)${(@)${(f)$(ipadm show-if -p -o state,ifname)}:#disabled:*}#*:}"
       
    15 }
       
    16 
       
    17 _ipadm_disabled_ifs() {
       
    18 	compadd "$@" - "${(@)${(@)${(f)$(ipadm show-if -p -o state,ifname)}#disabled:*}:#*:*}"
       
    19 }
       
    20 
       
    21 _ipadm_vnis() {
       
    22 	compadd "$@" - "${(@)${(@)${(f)$(ipadm show-if -p -o class,ifname)}#vni:*}:#*:*}"
       
    23 }
       
    24 
       
    25 _ipadm_ipmps() {
       
    26 	compadd "$@" - "${(@)${(@)${(f)$(ipadm show-if -p -o class,ifname)}#ipmp:*}:#*:*}"
       
    27 }
       
    28 
       
    29 _ipadm_get_possible_values() {
       
    30 	local -a proto poss
       
    31 	local cmd
       
    32 
       
    33 	cmd=${${(M)words:#set-*}/set/show}
       
    34 	if [[ $cmd == "show-prop" ]]; then
       
    35 		# You have to specify a protocol for show-prop if you specify a
       
    36 		# property, so we loop through them all.
       
    37 		poss=()
       
    38 		for proto in ipv4 ipv6 icmp tcp udp sctp; do
       
    39 			poss=( $poss ${(u)=$(ipadm $cmd -c -p ${IPREFIX%=} -o possible $proto 2> /dev/null)//,/ } )
       
    40 		done
       
    41 		poss=( ${(u)poss:#\?} )
       
    42 	else
       
    43 		proto=${=opt_args[-m]:+-m $opt_args[-m]}
       
    44 		poss=( ${(u)=$(ipadm $cmd -c -p ${IPREFIX%=} $proto -o possible)//,/ } )
       
    45 	fi
       
    46 	if [[ $poss[1] == [0-9]##-[0-9]## ]]; then
       
    47 		if (( $#poss > 1 )); then
       
    48 			_message -e "number in ranges ${(j:, :)poss}"
       
    49 		else
       
    50 			_message -e "number in range $poss"
       
    51 		fi
       
    52 	elif [[ -z $poss[1] ]]; then
       
    53 		_message -e "value"
       
    54 	else
       
    55 		compadd "$@" - $poss
       
    56 	fi
       
    57 }
       
    58 
       
    59 _ipadm_addrobjs() {
       
    60 	compadd "$@" - $(ipadm show-addr -p -o addrobj)
       
    61 }
       
    62 
       
    63 _ipadm_protos() {
       
    64 	compadd "$@" - $(ipadm show-prop -c -o proto)
       
    65 }
       
    66 
       
    67 _ipadm() {
       
    68 	local context state line expl
       
    69 	local -A opt_args
       
    70 	local -a subcmds
       
    71 	local -a if_properties if_propproperties if_properties2
       
    72 	local -a addr_properties addr_propproperties
       
    73 	local -a addrobj_properties
       
    74 	local -a proto_ipv4_properties proto_ipv6_properties proto_tcp_properties
       
    75 	local -a proto_udp_properties proto_sctp_properties proto_icmp_properties
       
    76 	local -a proto_all_properties proto_propproperties
       
    77 
       
    78 	subcmds=(
       
    79 		{"show","disable","enable"}"-if"
       
    80 		{"create","delete"}"-ip"
       
    81 		{"create","delete"}"-vni"
       
    82 		{"create","delete","add","remove"}"-ipmp"
       
    83 		{"set","reset","show"}"-ifprop"
       
    84 		{"create","delete","show","up","down","refresh","disable","enable"}"-addr"
       
    85 		{"set","reset","show"}"-addrprop"
       
    86 		{"set","reset","show"}"-prop"
       
    87 	)
       
    88 
       
    89 	if_properties=( "ifname" "class" "state" "active" "current" "persistent" "over" )
       
    90 
       
    91 	if_propproperties=( "ifname" "property" "proto" "perm" "current" "persistent" "default" "possible" )
       
    92 
       
    93 	if_properties2=(
       
    94 		"arp:value:_ipadm_get_possible_values"
       
    95 		"forwarding:value:_ipadm_get_possible_values"
       
    96 		"metric:value:_ipadm_get_possible_values"
       
    97 		"mtu:value:_ipadm_get_possible_values"
       
    98 		"nud:value:_ipadm_get_possible_values"
       
    99 		"usesrc:value:_ipadm_ifs -/ none"
       
   100 		"exchange_routes:value:_ipadm_get_possible_values"
       
   101 		"group:value:_ipadm_get_possible_values"
       
   102 		"standby:value:_ipadm_get_possible_values"
       
   103 	)
       
   104 
       
   105 	addr_properties=(
       
   106 		"broadcast:value:_ipadm_get_possible_values"
       
   107 		"deprecated:value:_ipadm_get_possible_values"
       
   108 		"prefixlen:value:_ipadm_get_possible_values"
       
   109 		"private:value:_ipadm_get_possible_values"
       
   110 		"reqhost:value:_ipadm_get_possible_values"
       
   111 		"transmit:value:_ipadm_get_possible_values"
       
   112 		"zone:value:_zones -t c"
       
   113 	)
       
   114 
       
   115 	addr_propproperties=( "addrobj" "property" "perm" "current" "persistent" "default" "possible" )
       
   116 
       
   117 	addrobj_properties=(
       
   118 		"addrobj" "type" "state" "current" "persistent" "addr"
       
   119 		"cid-type" "cid-value" "begin" "expire" "renew"
       
   120 	)
       
   121 
       
   122 	proto_ipv4_properties=( "hostmodel" "ttl" "forwarding" )
       
   123 	proto_ipv6_properties=( "hostmodel" "hoplimit" "forwarding" )
       
   124 	proto_tcp_properties=( "cong_default" "cong_enabled" "ecn" "extra_priv_ports" "max_buf" "recv_buf"
       
   125 		"send_buf" "sack" "smallest_anon_port" "largest_anon_port" "smallest_nonpriv_port" )
       
   126 	proto_udp_properties=( "extra_priv_ports" "max_buf" "recv_buf" "send_buf" "smallest_anon_port"
       
   127 		"largest_anon_port" "smallest_nonpriv_port" )
       
   128 	proto_sctp_properties=( "cong_default" "cong_enabled" "extra_priv_ports" "max_buf" "recv_buf"
       
   129 		"send_buf" "smallest_anon_port" "largest_anon_port" "smallest_nonpriv_port" )
       
   130 	proto_icmp_properties=( "max_buf" "recv_buf" "send_buf" )
       
   131 	proto_all_properties=( $proto_ipv4_properties $proto_ipv6_properties $proto_tcp_properties
       
   132 		$proto_udp_properties $proto_sctp_properties $proto_icmp_properties )
       
   133 	proto_all_properties=( $^proto_all_properties:value:_ipadm_get_possible_values )
       
   134 
       
   135 	proto_propproperties=( "proto" "property" "perm" "current" "persistent" "default" "possible" )
       
   136 
       
   137 	if [[ $service == "ipadm" ]]; then
       
   138 		_arguments -C -A "-*" \
       
   139 			'-\?[Help]' \
       
   140 			'*::command:->subcmd' && return 0
       
   141 
       
   142 		if (( CURRENT == 1 )); then
       
   143 			_wanted commands expl "ipadm subcommand" compadd -a subcmds
       
   144 			return
       
   145 		fi
       
   146 		service="$words[1]"
       
   147 		curcontext="${curcontext%:*}=$service:"
       
   148 	fi
       
   149 
       
   150 	case $service in
       
   151 	("create-ip")
       
   152 		_arguments -A "-*" \
       
   153 			'(-t --temporary)'{-t,--temporary}'[Interface should be temporary]' \
       
   154 			':interface name:'
       
   155 		;;
       
   156 
       
   157 	("delete-ip")
       
   158 		_arguments -A "-*" \
       
   159 			':interface name:_ipadm_ifs'
       
   160 		;;
       
   161 
       
   162 	("create-vni")
       
   163 		_arguments -A "-*" \
       
   164 			'(-t --temporary)'{-t,--temporary}'[Interface should be temporary]' \
       
   165 			':VNI name:'
       
   166 		;;
       
   167 
       
   168 	("delete-vni")
       
   169 		_arguments -A "-*" \
       
   170 			':VNI name:_ipadm_vnis'
       
   171 		;;
       
   172 
       
   173 	("create-ipmp")
       
   174 		_arguments -A "-*" \
       
   175 			'(-t --temporary)'{-t,--temporary}'[Interface should be temporary]' \
       
   176 			'(-i --interface)'{-i,--interface}'[List of underlying interfaces]:interface name:_values -s , "interface" $(ipadm show-if -p -o ifname)' \
       
   177 			':IPMP interface name:'
       
   178 		;;
       
   179 
       
   180 	("delete-ipmp")
       
   181 		_arguments -A "-*" \
       
   182 			'(-f --force)'{-f,--force}'[First remove all underlying interfaces from group]' \
       
   183 			':IPMP interface name:_ipadm_ipmps'
       
   184 		;;
       
   185 
       
   186 	("add-ipmp")
       
   187 		_arguments -A "-*" \
       
   188 			'(-t --temporary)'{-t,--temporary}'[Interface should be temporary]' \
       
   189 			'(-i --interface)'{-i,--interface}'[List of underlying interfaces]:interface name:_values -s , "interface" $(ipadm show-if -p -o ifname)' \
       
   190 			':IPMP interface name:_ipadm_ipmps'
       
   191 		;;
       
   192 
       
   193 	("remove-ipmp")
       
   194 		_arguments -A "-*" \
       
   195 			'(-t --temporary)'{-t,--temporary}'[Interface should be temporary]' \
       
   196 			'(-i --interface)'{-i,--interface}'[List of underlying interfaces]:interface name:_values -s , "interface" $(ipadm show-if -p -o ifname)' \
       
   197 			':IPMP interface name:_ipadm_ipmps'
       
   198 		;;
       
   199 
       
   200 	("show-if")
       
   201 		_arguments -A "-*" \
       
   202 			'(-p --parseable)'{-p,--parseable}'[Parseable output]' \
       
   203 			'(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $if_properties' \
       
   204 			':interface name:_ipadm_ifs'
       
   205 		;;
       
   206 
       
   207 	("disable-if")
       
   208 		_arguments -A "-*" \
       
   209 			'(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
       
   210 			':interface name:_ipadm_enabled_ifs'
       
   211 		;;
       
   212 
       
   213 	("enable-if")
       
   214 		_arguments -A "-*" \
       
   215 			'(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
       
   216 			':interface name:_ipadm_disabled_ifs'
       
   217 		;;
       
   218 
       
   219 	("set-ifprop")
       
   220 		_arguments -A "-*" \
       
   221 			'(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
       
   222 			'(-m --module)'{-m,--module}'[Protocol]:protocol:(ipv4 ipv6)' \
       
   223 			'(-p --prop)'{-p,--prop}'[Property to set]:property:_values -s , "property" $if_properties2' \
       
   224 			':interface name:_ipadm_ifs'
       
   225 		;;
       
   226 
       
   227 	("reset-ifprop")
       
   228 		_arguments -A "-*" \
       
   229 			'(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
       
   230 			'(-m --module)'{-m,--module}'[Protocol]:protocol:(ipv4 ipv6)' \
       
   231 			'(-p --prop)'{-p,--prop}'[Property to reset]:property:($if_properties2)' \
       
   232 			':interface name:_ipadm_ifs'
       
   233 		;;
       
   234 
       
   235 	("show-ifprop")
       
   236 		_arguments -A "-*" \
       
   237 			'(-c --parseable)'{-c,--parseable}'[Parseable output]' \
       
   238 			'(-m --module)'{-m,--module}'[Protocol]:protocol:(ipv4 ipv6)' \
       
   239 			'(-o --output)'{-o,--output}'[Property properties to display]:property:_values -s , "property" $if_propproperties' \
       
   240 			'(-p --prop)'{-p,--prop}'[Interface properties to display]:property:_values -s , "property" ${if_properties2%%\:*}' \
       
   241 			':interface name:_ipadm_ifs'
       
   242 		;;
       
   243 
       
   244 	("create-addr")
       
   245 		# This causes all options and arguments following -T to be
       
   246 		# stuck into $opt_args[-T].  It feels hacky, but it seems
       
   247 		# to do the trick.
       
   248 		_arguments -C -A "-*" \
       
   249 			'(-t --temporary)'{-t,--temporary}'[Address should be temporary]' \
       
   250 			'-T[Address type]:*::address type:->newaddr'
       
   251 
       
   252 		if [[ $state == "newaddr" ]]; then
       
   253 
       
   254 			case ${opt_args[-T]#-T:} in
       
   255 			("static:"*)
       
   256 				local -a addrthingsv4
       
   257 				addrthingsv4=( "local:address: " "remote:address: ")
       
   258 				_arguments -A "-*" \
       
   259 				'(-d --down)'{-d,--down}'[Address should be marked down]' \
       
   260 				'(-a --address)'{-a,--address}'[Address specification]:address:_values -s , "address" $addrthingsv4' \
       
   261 				':address object name:_ipadm_addrobjs'
       
   262 				;;
       
   263 
       
   264 			("dhcp:"*)
       
   265 				_arguments -A "-*" \
       
   266 				'(-w --wait)'{-w,--wait}'[Seconds to wait for completion]:number or "forever":{if [[ -prefix [0-9]## ]]; then _message -e "number of seconds"; else _wanted forever expl "number or \"forever\"" compadd forever; fi}' \
       
   267 				'-h[Request a specific hostname]:hostname:' \
       
   268 				':address object name:_ipadm_addrobjs'
       
   269 				;;
       
   270 
       
   271 			("addrconf:"*)
       
   272 				local -a addrthingsv6 statefulness
       
   273 				addrthingsv6=( "local:interface id: " "remote:interface id: ")
       
   274 				statefulness=( "stateful:statefulness:(yes no)" "stateless:statelessness:(yes no)" )
       
   275 				_arguments -A "-*" \
       
   276 				'(-i --interface-id)'{-i,--interface-id}'[Interface ID]:address:_values -s , "interface id" $addrthingsv6' \
       
   277 				'(-p --prop)'{-p,--prop}'[Statefulness configuration]:statefulness configuration:_values -s , "statefulness" $statefulness' \
       
   278 				':address object name:_ipadm_addrobjs'
       
   279 				;;
       
   280 			(*)
       
   281 				_wanted commands expl "address type" compadd static dhcp addrconf
       
   282 				;;
       
   283 			esac
       
   284 		fi
       
   285 
       
   286 		;;
       
   287 
       
   288 	("delete-addr")
       
   289 		_arguments -A "-*" \
       
   290 			'(-r --release)'{-r,--release}'[Release DHCP-acquired address]' \
       
   291 			':address object name:_ipadm_addrobjs'
       
   292 		;;
       
   293 
       
   294 	("show-addr")
       
   295 		_arguments -A "-*" \
       
   296 			'(-d --dhcp -p --parseable)'{-d,--dhcp}'[Display DHCP status fields]' \
       
   297 			'(-p --parseable -d --dhcp)'{-p,--parseable}'[Parseable output]' \
       
   298 			'(-o --output)'{-o,--output}'[Properties to display]:property:_values -s , "property" $addrobj_properties' \
       
   299 			':address object name:_ipadm_addrobjs'
       
   300 		;;
       
   301 
       
   302 	({"up","down","disable","enable"}"-addr")
       
   303 		_arguments -A "-*" \
       
   304 			'(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
       
   305 			':address object name:_ipadm_addrobjs'
       
   306 		;;
       
   307 
       
   308 	("refresh-addr")
       
   309 		_arguments -A "-*" \
       
   310 			'(-i --inform)'{-i,--inform}'[Retrieve DHCP parameters]' \
       
   311 			':address object name:_ipadm_addrobjs'
       
   312 		;;
       
   313 
       
   314 	("set-addrprop")
       
   315 		_arguments -A "-*" \
       
   316 			'(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
       
   317 			'(-p --prop)'{-p,--prop}'[Property to set]:property:_values -s , "property" $addr_properties' \
       
   318 			':address object name:_ipadm_addrobjs'
       
   319 		;;
       
   320 
       
   321 	("reset-addrprop")
       
   322 		_arguments -A "-*" \
       
   323 			'(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
       
   324 			'(-p --prop)'{-p,--prop}'[Property to reset]:property:(${addr_properties%%\:*})' \
       
   325 			':address object name:_ipadm_addrobjs'
       
   326 		;;
       
   327 
       
   328 	("show-addrprop")
       
   329 		_arguments -A "-*" \
       
   330 			'(-c --parseable)'{-c,--parseable}'[Parseable output]' \
       
   331 			'(-o --output)'{-o,--output}'[Property properties to display]:property:_values -s , "property" $addr_propproperties' \
       
   332 			'(-p --prop)'{-p,--prop}'[Address object properties to display]:property:_values -s , "property" ${addr_properties%%\:*}' \
       
   333 			':address object name:_ipadm_addrobjs'
       
   334 		;;
       
   335 
       
   336 	("set-prop")
       
   337 		_arguments -A "-*" \
       
   338 			'(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
       
   339 			'(-p --prop)'{-p,--prop}'[Property to set]:property:_values -s , "property" $proto_all_properties' \
       
   340 			':protocol name:_ipadm_protos'
       
   341 		;;
       
   342 
       
   343 	("reset-prop")
       
   344 		_arguments -A "-*" \
       
   345 			'(-t --temporary)'{-t,--temporary}'[Change should be temporary]' \
       
   346 			'(-p --prop)'{-p,--prop}'[Property to reset]:property:(${proto_all_properties%%\:*})' \
       
   347 			':protocol name:_ipadm_protos'
       
   348 		;;
       
   349 
       
   350 	("show-prop")
       
   351 		_arguments -A "-*" \
       
   352 			'(-c --parseable)'{-c,--parseable}'[Parseable output]' \
       
   353 			'(-o --output)'{-o,--output}'[Property properties to display]:property:_values -s , "property" $proto_propproperties' \
       
   354 			'(-p --prop)'{-p,--prop}'[Protocol properties to display]:property:_values -s , "property" ${proto_all_properties%%\:*}' \
       
   355 			':protocol name:_ipadm_protos'
       
   356 		;;
       
   357 
       
   358 	(*)
       
   359 		_message "unknown ipadm subcommand: $service"
       
   360 		;;
       
   361 	esac
       
   362 }
       
   363 
       
   364 _ipadm "$@"