2 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, Daniil Lunev. All rights reserved.
4 * Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
7 * Copyright (c) 1983 Regents of the University of California.
8 * All rights reserved. The Berkeley software License Agreement
9 * specifies the terms and conditions for redistribution.
17 #include <libdllink.h>
18 #include <libdliptun.h>
19 #include <libdllink.h>
21 #include <inet/ipsec_impl.h>
24 #include <libsocket_priv.h>
26 #define LOOPBACK_IF "lo0"
27 #define NONE_STR "none"
28 #define ARP_MOD_NAME "arp"
29 #define LIFC_DEFAULT (LIFC_NOXMIT | LIFC_TEMPORARY | LIFC_ALLZONES |\
32 typedef struct if_flags
{
37 static if_flags_t if_flags_tbl
[] = {
39 { IFF_BROADCAST
, "BROADCAST" },
40 { IFF_DEBUG
, "DEBUG" },
41 { IFF_LOOPBACK
, "LOOPBACK" },
42 { IFF_POINTOPOINT
, "POINTOPOINT" },
43 { IFF_NOTRAILERS
, "NOTRAILERS" },
44 { IFF_RUNNING
, "RUNNING" },
45 { IFF_NOARP
, "NOARP" },
46 { IFF_PROMISC
, "PROMISC" },
47 { IFF_ALLMULTI
, "ALLMULTI" },
48 { IFF_INTELLIGENT
, "INTELLIGENT" },
49 { IFF_MULTICAST
, "MULTICAST" },
50 { IFF_MULTI_BCAST
, "MULTI_BCAST" },
51 { IFF_UNNUMBERED
, "UNNUMBERED" },
52 { IFF_DHCPRUNNING
, "DHCP" },
53 { IFF_PRIVATE
, "PRIVATE" },
54 { IFF_NOXMIT
, "NOXMIT" },
55 { IFF_NOLOCAL
, "NOLOCAL" },
56 { IFF_DEPRECATED
, "DEPRECATED" },
57 { IFF_ADDRCONF
, "ADDRCONF" },
58 { IFF_ROUTER
, "ROUTER" },
59 { IFF_NONUD
, "NONUD" },
60 { IFF_ANYCAST
, "ANYCAST" },
61 { IFF_NORTEXCH
, "NORTEXCH" },
64 { IFF_NOFAILOVER
, "NOFAILOVER" },
65 { IFF_FAILED
, "FAILED" },
66 { IFF_STANDBY
, "STANDBY" },
67 { IFF_INACTIVE
, "INACTIVE" },
68 { IFF_OFFLINE
, "OFFLINE" },
69 { IFF_XRESOLV
, "XRESOLV" },
70 { IFF_COS_ENABLED
, "CoS" },
71 { IFF_PREFERRED
, "PREFERRED" },
72 { IFF_TEMPORARY
, "TEMPORARY" },
73 { IFF_FIXEDMTU
, "FIXEDMTU" },
74 { IFF_VIRTUAL
, "VIRTUAL" },
75 { IFF_DUPLICATE
, "DUPLICATE" },
78 { IFF_NOACCEPT
, "NOACCEPT"},
79 { IFF_L3PROTECT
, "L3PROTECT"}
88 static const if_appflags_t if_appflags_tbl
[] = {
89 { "dhcpagent(1M)", IFF_DHCPRUNNING
, 1 },
90 { "in.ndpd(1M)", IFF_ADDRCONF
, 3 },
94 static dladm_handle_t dlh
;
96 static struct lifreq lifr
;
97 /* current interface name a particular function is accessing */
98 static char name
[LIFNAMSIZ
];
99 /* foreach interface saved name */
100 static char origname
[LIFNAMSIZ
];
102 static boolean_t setaddr_done
= _B_FALSE
;
103 static boolean_t ipsec_policy_set
;
104 static boolean_t ipsec_auth_covered
;
105 static ipadm_handle_t iph
;
106 static ipadm_addrobj_t ipaddr
;
109 * Make sure the algorithm variables hold more than the sizeof an algorithm
110 * in PF_KEY. (For now, more than a uint8_t.) The NO_***_?ALG indicates that
111 * there was no algorithm requested, and in the ipsec_req that service should
112 * be disabled. (E.g. if ah_aalg remains NO_AH_AALG, then AH will be
113 * disabled on that tunnel.)
115 #define NO_AH_AALG 256
116 #define NO_ESP_AALG 256
117 #define NO_ESP_EALG 256
120 int af
= AF_INET
; /* default address family */
122 int all
= 0; /* setifdhcp() needs to know this */
124 int v4compat
= 0; /* Compatible printing format */
127 * Function prototypes for command functions.
129 static int addif(char *arg
, int64_t param
);
130 static int inetipmp(char *arg
, int64_t param
);
131 static int inetplumb(char *arg
, int64_t param
);
132 static int inetunplumb(char *arg
, int64_t param
);
133 static int removeif(char *arg
, int64_t param
);
134 static int setdebugflag(char *arg
, int64_t param
);
135 static int setifaddr(char *arg
, int64_t param
);
136 static int setifbroadaddr(char *arg
, int64_t param
);
137 static int setifdstaddr(char *arg
, int64_t param
);
138 static int setifether(char *arg
, int64_t param
);
139 static int setifflags(char *arg
, int64_t param
);
140 static int setifindex(char *arg
, int64_t param
);
141 static int setifmetric(char *arg
, int64_t param
);
142 static int setifmtu(char *arg
, int64_t param
);
143 static int setifnetmask(char *arg
, int64_t param
);
144 static int setifprefixlen(char *arg
, int64_t param
);
145 static int setifrevarp(char *arg
, int64_t param
);
146 static int setifsubnet(char *arg
, int64_t param
);
147 static int setiftdst(char *arg
, int64_t param
);
148 static int setiftoken(char *arg
, int64_t param
);
149 static int setiftsrc(char *arg
, int64_t param
);
150 static int setverboseflag(char *arg
, int64_t param
);
151 static int set_tun_ah_alg(char *arg
, int64_t param
);
152 static int set_tun_esp_auth_alg(char *arg
, int64_t param
);
153 static int set_tun_esp_encr_alg(char *arg
, int64_t param
);
154 static int modlist(char *arg
, int64_t param
);
155 static int modinsert(char *arg
, int64_t param
);
156 static int modremove(char *arg
, int64_t param
);
157 static int setifgroupname(char *arg
, int64_t param
);
158 static int configinfo(char *arg
, int64_t param
);
159 static void print_config_flags(int af
, uint64_t flags
);
160 static void print_flags(uint64_t flags
);
161 static void print_ifether(const char *ifname
);
162 static int set_tun_encap_limit(char *arg
, int64_t param
);
163 static int clr_tun_encap_limit(char *arg
, int64_t param
);
164 static int set_tun_hop_limit(char *arg
, int64_t param
);
165 static int setzone(char *arg
, int64_t param
);
166 static int setallzones(char *arg
, int64_t param
);
167 static int setifsrc(char *arg
, int64_t param
);
168 static int lifnum(const char *ifname
);
169 static void plumball(int, char **, int64_t, int64_t, int64_t);
172 * Address family specific function prototypes.
174 static void in_getaddr(char *s
, struct sockaddr
*saddr
, int *plenp
);
175 static void in_status(int force
, uint64_t flags
);
176 static void in_configinfo(int force
, uint64_t flags
);
177 static void in6_getaddr(char *s
, struct sockaddr
*saddr
, int *plenp
);
178 static void in6_status(int force
, uint64_t flags
);
179 static void in6_configinfo(int force
, uint64_t flags
);
182 * Misc support functions
184 static boolean_t
ni_entry(const char *, void *);
185 static void foreachinterface(int argc
, char *argv
[],
186 int af
, int64_t onflags
, int64_t offflags
,
188 static void ifconfig(int argc
, char *argv
[], int af
,
189 struct ifaddrs
*ifa
);
190 static boolean_t
in_getmask(struct sockaddr_in
*saddr
,
192 static int in_getprefixlen(char *addr
, boolean_t slash
, int plen
);
193 static boolean_t
in_prefixlentomask(int prefixlen
, int maxlen
,
195 static void status(void);
196 static void ifstatus(const char *ifname
);
197 static void tun_status(datalink_id_t
);
198 static void usage(void);
199 static int setifdhcp(const char *caller
, const char *ifname
,
200 int argc
, char *argv
[]);
201 static int ip_domux2fd(int *, int *, int *, int *, int *);
202 static int ip_plink(int, int, int, int, int);
203 static int modop(char *arg
, char op
);
204 static int find_all_interfaces(struct lifconf
*lifcp
, char **buf
,
206 static int create_ipmp(const char *grname
, int af
,
207 const char *ifname
, boolean_t implicit
);
208 static void start_ipmp_daemon(void);
209 static boolean_t
ifaddr_up(ifaddrlistx_t
*ifaddrp
);
210 static boolean_t
ifaddr_down(ifaddrlistx_t
*ifaddrp
);
211 static dladm_status_t
ifconfig_dladm_open(const char *, datalink_class_t
,
213 static void dladmerr_exit(dladm_status_t status
, const char *str
);
214 static void ipadmerr_exit(ipadm_status_t status
, const char *str
);
215 static boolean_t
ifconfig_use_libipadm(int, const char *);
217 #define max(a, b) ((a) < (b) ? (b) : (a))
220 * DHCP_EXIT_IF_FAILURE indicates that the operation failed, but if there
221 * are more interfaces to act on (i.e., ifconfig was invoked with -a), keep
222 * on going rather than exit with an error.
225 #define DHCP_EXIT_IF_FAILURE -1
227 #define NEXTARG 0xffffff /* command takes an argument */
228 #define OPTARG 0xfffffe /* command takes an optional argument */
231 /* Refer to the comments in ifconfig() on the netmask "hack" */
232 #define NETMASK_CMD "netmask"
233 struct sockaddr_storage g_netmask
;
234 enum { G_NETMASK_NIL
, G_NETMASK_PENDING
, G_NETMASK_SET
}
235 g_netmask_set
= G_NETMASK_NIL
;
239 int64_t c_parameter
; /* NEXTARG means next argv */
240 int (*c_func
)(char *, int64_t);
241 int c_abortonfail
; /* don't continue parsing args */
242 /* for the current interface */
243 int c_af
; /* address family restrictions */
245 { "up", IFF_UP
, setifflags
, 0, AF_ANY
},
246 { "down", -IFF_UP
, setifflags
, 0, AF_ANY
},
247 { "trailers", -IFF_NOTRAILERS
, setifflags
, 0, AF_ANY
},
248 { "-trailers", IFF_NOTRAILERS
, setifflags
, 0, AF_ANY
},
249 { "arp", -IFF_NOARP
, setifflags
, 0, AF_INET
},
250 { "-arp", IFF_NOARP
, setifflags
, 0, AF_INET
},
251 { "router", IFF_ROUTER
, setifflags
, 0, AF_ANY
},
252 { "-router", -IFF_ROUTER
, setifflags
, 0, AF_ANY
},
253 { "private", IFF_PRIVATE
, setifflags
, 0, AF_ANY
},
254 { "-private", -IFF_PRIVATE
, setifflags
, 0, AF_ANY
},
255 { "xmit", -IFF_NOXMIT
, setifflags
, 0, AF_ANY
},
256 { "-xmit", IFF_NOXMIT
, setifflags
, 0, AF_ANY
},
257 { "-nud", IFF_NONUD
, setifflags
, 0, AF_INET6
},
258 { "nud", -IFF_NONUD
, setifflags
, 0, AF_INET6
},
259 { "anycast", IFF_ANYCAST
, setifflags
, 0, AF_ANY
},
260 { "-anycast", -IFF_ANYCAST
, setifflags
, 0, AF_ANY
},
261 { "local", -IFF_NOLOCAL
, setifflags
, 0, AF_ANY
},
262 { "-local", IFF_NOLOCAL
, setifflags
, 0, AF_ANY
},
263 { "deprecated", IFF_DEPRECATED
, setifflags
, 0, AF_ANY
},
264 { "-deprecated", -IFF_DEPRECATED
, setifflags
, 0, AF_ANY
},
265 { "preferred", IFF_PREFERRED
, setifflags
, 0, AF_INET6
},
266 { "-preferred", -IFF_PREFERRED
, setifflags
, 0, AF_INET6
},
267 { "debug", 0, setdebugflag
, 0, AF_ANY
},
268 { "verbose", 0, setverboseflag
, 0, AF_ANY
},
269 { NETMASK_CMD
, NEXTARG
, setifnetmask
, 0, AF_INET
},
270 { "metric", NEXTARG
, setifmetric
, 0, AF_ANY
},
271 { "mtu", NEXTARG
, setifmtu
, 0, AF_ANY
},
272 { "index", NEXTARG
, setifindex
, 0, AF_ANY
},
273 { "broadcast", NEXTARG
, setifbroadaddr
, 0, AF_INET
},
274 { "auto-revarp", 0, setifrevarp
, 1, AF_INET
},
275 { "ipmp", 0, inetipmp
, 1, AF_ANY
},
276 { "plumb", 0, inetplumb
, 1, AF_ANY
},
277 { "unplumb", 0, inetunplumb
, 0, AF_ANY
},
278 { "subnet", NEXTARG
, setifsubnet
, 0, AF_ANY
},
279 { "token", NEXTARG
, setiftoken
, 0, AF_INET6
},
280 { "tsrc", NEXTARG
, setiftsrc
, 0, AF_ANY
},
281 { "tdst", NEXTARG
, setiftdst
, 0, AF_ANY
},
282 { "encr_auth_algs", NEXTARG
, set_tun_esp_auth_alg
, 0, AF_ANY
},
283 { "encr_algs", NEXTARG
, set_tun_esp_encr_alg
, 0, AF_ANY
},
284 { "auth_algs", NEXTARG
, set_tun_ah_alg
, 0, AF_ANY
},
285 { "addif", NEXTARG
, addif
, 1, AF_ANY
},
286 { "removeif", NEXTARG
, removeif
, 1, AF_ANY
},
287 { "modlist", 0, modlist
, 1, AF_ANY
},
288 { "modinsert", NEXTARG
, modinsert
, 1, AF_ANY
},
289 { "modremove", NEXTARG
, modremove
, 1, AF_ANY
},
290 { "failover", -IFF_NOFAILOVER
, setifflags
, 1, AF_ANY
},
291 { "-failover", IFF_NOFAILOVER
, setifflags
, 1, AF_ANY
},
292 { "standby", IFF_STANDBY
, setifflags
, 1, AF_ANY
},
293 { "-standby", -IFF_STANDBY
, setifflags
, 1, AF_ANY
},
294 { "failed", IFF_FAILED
, setifflags
, 1, AF_ANY
},
295 { "-failed", -IFF_FAILED
, setifflags
, 1, AF_ANY
},
296 { "group", NEXTARG
, setifgroupname
, 1, AF_ANY
},
297 { "configinfo", 0, configinfo
, 1, AF_ANY
},
298 { "encaplimit", NEXTARG
, set_tun_encap_limit
, 0, AF_ANY
},
299 { "-encaplimit", 0, clr_tun_encap_limit
, 0, AF_ANY
},
300 { "thoplimit", NEXTARG
, set_tun_hop_limit
, 0, AF_ANY
},
301 { "set", NEXTARG
, setifaddr
, 0, AF_ANY
},
302 { "destination", NEXTARG
, setifdstaddr
, 0, AF_ANY
},
303 { "zone", NEXTARG
, setzone
, 0, AF_ANY
},
304 { "-zone", 0, setzone
, 0, AF_ANY
},
305 { "all-zones", 0, setallzones
, 0, AF_ANY
},
306 { "ether", OPTARG
, setifether
, 0, AF_ANY
},
307 { "usesrc", NEXTARG
, setifsrc
, 0, AF_ANY
},
310 * NOTE: any additions to this table must also be applied to ifparse
311 * (usr/src/cmd/cmd-inet/sbin/ifparse/ifparse.c)
314 { 0, 0, setifaddr
, 0, AF_ANY
},
315 { 0, 0, setifdstaddr
, 0, AF_ANY
},
320 typedef struct if_config_cmd
{
327 * NOTE: print_config_flags() processes this table in order, so we put "up"
328 * last so that we can be sure "-failover" will take effect first. Otherwise,
329 * IPMP test addresses will erroneously migrate to the IPMP interface.
331 static if_config_cmd_t if_config_cmd_tbl
[] = {
332 { IFF_NOTRAILERS
, AF_UNSPEC
, "-trailers" },
333 { IFF_PRIVATE
, AF_UNSPEC
, "private" },
334 { IFF_NOXMIT
, AF_UNSPEC
, "-xmit" },
335 { IFF_ANYCAST
, AF_INET6
, "anycast" },
336 { IFF_NOLOCAL
, AF_UNSPEC
, "-local" },
337 { IFF_DEPRECATED
, AF_UNSPEC
, "deprecated" },
338 { IFF_NOFAILOVER
, AF_UNSPEC
, "-failover" },
339 { IFF_STANDBY
, AF_UNSPEC
, "standby" },
340 { IFF_FAILED
, AF_UNSPEC
, "failed" },
341 { IFF_PREFERRED
, AF_UNSPEC
, "preferred" },
342 { IFF_NONUD
, AF_INET6
, "-nud" },
343 { IFF_NOARP
, AF_INET
, "-arp" },
344 { IFF_UP
, AF_UNSPEC
, "up" },
349 char ni_name
[LIFNAMSIZ
];
353 static ni_t
*ni_list
= NULL
;
354 static int num_ni
= 0;
356 /* End defines and structure definitions for ifconfig -a plumb */
358 /* Known address families */
363 void (*af_getaddr
)();
364 void (*af_configinfo
)();
366 { "inet", AF_INET
, in_status
, in_getaddr
, in_configinfo
},
367 { "inet6", AF_INET6
, in6_status
, in6_getaddr
, in6_configinfo
},
371 #define SOCKET_AF(af) (((af) == AF_UNSPEC) ? AF_INET : (af))
373 struct afswtch
*afp
; /* the address family being set or asked about */
376 main(int argc
, char *argv
[])
379 char *default_ip_str
;
380 ipadm_status_t istatus
;
382 lifc_flags
= LIFC_DEFAULT
;
385 (void) strncpy(name
, "-a", sizeof (name
));
388 if (strlen(*argv
) > sizeof (name
) - 1) {
389 (void) fprintf(stderr
, "%s: interface name too long\n",
393 (void) strncpy(name
, *argv
, sizeof (name
));
395 name
[sizeof (name
) - 1] = '\0';
396 (void) strncpy(origname
, name
, sizeof (origname
)); /* For addif */
397 default_ip_str
= NULL
;
398 v4compat
= get_compat_flag(&default_ip_str
);
399 if (v4compat
== DEFAULT_PROT_BAD_VALUE
) {
400 (void) fprintf(stderr
,
401 "ifconfig: %s: Bad value for %s in %s\n", default_ip_str
,
402 DEFAULT_IP
, INET_DEFAULT_FILE
);
403 free(default_ip_str
);
406 free(default_ip_str
);
409 struct afswtch
*myafp
;
411 for (myafp
= afp
= afs
; myafp
->af_name
; myafp
++) {
412 if (strcmp(myafp
->af_name
, *argv
) == 0) {
413 afp
= myafp
; argc
--; argv
++;
417 af
= lifr
.lifr_addr
.ss_family
= afp
->af_af
;
418 if (af
== AF_INET6
) {
423 s
= socket(SOCKET_AF(af
), SOCK_DGRAM
, 0);
424 s4
= socket(AF_INET
, SOCK_DGRAM
, 0);
425 s6
= socket(AF_INET6
, SOCK_DGRAM
, 0);
426 if (s
== -1 || s4
== -1 || s6
== -1)
427 Perror0_exit("socket");
429 * Open the global libipadm handle. The flag IPH_LEGACY has to
430 * be specified to indicate that logical interface names will
431 * be used during interface creation and address creation.
433 if ((istatus
= ipadm_open(&iph
, IPH_LEGACY
)) != IPADM_SUCCESS
)
434 ipadmerr_exit(istatus
, "unable to open handle to libipadm");
437 * Special interface names is any combination of these flags.
438 * Note that due to the ifconfig syntax they have to be combined
439 * as a single '-' option.
442 * -d "down" interfaces
443 * -D Interfaces not controlled by DHCP
446 * -X Turn on debug (not documented)
448 * -Z Only interfaces in caller's zone
451 if (name
[0] == '-') {
452 /* One or more options */
454 int64_t offflags
= 0;
456 char *av
[2] = { "ifconfig", name
};
458 while ((c
= getopt(2, av
, "audhDXZ46v")) != -1) {
470 offflags
|= IFF_DHCPRUNNING
;
476 lifc_flags
&= ~LIFC_ALLZONES
;
480 * -4 is not a compatable flag, therefore
481 * we assume they want v4compat turned off
488 * If they want IPv6, well then we'll assume
489 * they don't want IPv4 compat
504 (void) fprintf(stderr
,
505 "ifconfig: %s: no such interface\n", name
);
508 foreachinterface(argc
, argv
, af
, onflags
, offflags
,
511 ifconfig(argc
, argv
, af
, NULL
);
518 * For each interface, call ifconfig(argc, argv, af, ifa).
519 * Only call function if onflags and offflags are set or clear, respectively,
520 * in the interfaces flags field.
523 foreachinterface(int argc
, char *argv
[], int af
,
524 int64_t onflags
, int64_t offflags
, int64_t lifc_flags
)
526 ipadm_addr_info_t
*ainfo
, *ainfop
;
528 ipadm_status_t istatus
;
532 * ifconfig -a plumb should find all network interfaces in the current
535 if (argc
> 0 && (strcmp(*argv
, "plumb") == 0)) {
536 plumball(argc
, argv
, onflags
, offflags
, lifc_flags
);
539 /* Get all addresses in kernel including addresses that are zero. */
540 istatus
= ipadm_addr_info(iph
, NULL
, &ainfo
, IPADM_OPT_ZEROADDR
,
542 if (istatus
!= IPADM_SUCCESS
)
543 ipadmerr_exit(istatus
, "could not get addresses from kernel");
546 * For each logical interface, call ifconfig() with the
549 for (ainfop
= ainfo
; ainfop
!= NULL
; ainfop
= IA_NEXT(ainfop
)) {
550 if (ainfop
->ia_state
== IFA_DISABLED
)
552 ifa
= &ainfop
->ia_ifa
;
553 if (onflags
|| offflags
) {
554 if ((ifa
->ifa_flags
& onflags
) != onflags
)
556 if ((~ifa
->ifa_flags
& offflags
) != offflags
)
559 s
= (ifa
->ifa_addr
->sa_family
== AF_INET
? s4
: s6
);
560 (void) strncpy(name
, ifa
->ifa_name
, sizeof (name
));
561 (void) strncpy(origname
, name
, sizeof (origname
));
562 ifconfig(argc
, argv
, af
, ifa
);
564 ipadm_free_addr_info(ainfo
);
568 * Used for `ifconfig -a plumb'. Finds all datalinks and plumbs the interface.
571 plumball(int argc
, char *argv
[], int64_t onflags
, int64_t offflags
,
575 struct lifreq
*lifrp
;
579 if (onflags
!= 0 || offflags
!= 0) {
580 (void) fprintf(stderr
, "ifconfig: invalid syntax used to "
581 "plumb all interfaces.\n");
585 if (find_all_interfaces(&lifc
, &buf
, lifc_flags
) != 0 ||
589 lifrp
= lifc
.lifc_req
;
590 for (n
= lifc
.lifc_len
/ sizeof (struct lifreq
); n
> 0; n
--, lifrp
++) {
593 * setaddr: Used by parser to tear apart source and dest
594 * name and origname contain the name of the 'current'
598 (void) strncpy(name
, lifrp
->lifr_name
, sizeof (name
));
599 (void) strncpy(origname
, name
, sizeof (origname
));
600 ifconfig(argc
, argv
, af
, NULL
);
605 * Parses the interface name and the command in argv[]. Calls the
606 * appropriate callback function for the given command from `cmds[]'
608 * If there is no command specified, it prints all addresses.
611 ifconfig(int argc
, char *argv
[], int af
, struct ifaddrs
*ifa
)
613 static boolean_t scan_netmask
= _B_FALSE
;
615 ipadm_status_t istatus
;
623 if (strcmp(*argv
, "auto-dhcp") == 0 || strcmp(*argv
, "dhcp") == 0) {
625 * Some errors are ignored in the case where more than one
626 * interface is being operated on.
628 ret
= setifdhcp("ifconfig", name
, argc
, argv
);
629 if (ret
== DHCP_EXIT_IF_FAILURE
) {
631 exit(DHCP_EXIT_FAILURE
);
632 } else if (ret
!= DHCP_EXIT_SUCCESS
) {
639 * The following is a "hack" to get around the existing interface
640 * setting mechanism. Currently, each interface attribute,
641 * such as address, netmask, broadcast, ... is set separately. But
642 * sometimes two or more attributes must be set together. For
643 * example, setting an address without a netmask does not make sense.
644 * Yet they can be set separately for IPv4 address using the current
645 * ifconfig(1M) syntax. The kernel then "infers" the correct netmask
646 * using the deprecated "IP address classes." This is simply not
649 * The "hack" below is to go thru the whole command list looking for
650 * the netmask command first. Then use this netmask to set the
651 * address. This does not provide an extensible way to accommodate
652 * future need for setting more than one attributes together.
654 * Note that if the "netmask" command argument is a "+", we need
655 * to save this info and do the query after we know the address to
656 * be set. The reason is that if "addif" is used, the working
657 * interface name will be changed later when the logical interface
658 * is created. In in_getmask(), if an address is not provided,
659 * it will use the working interface's address to do the query.
660 * It will be wrong now as we don't know the logical interface's name.
662 * ifconfig(1M) is too overloaded and the code is so convoluted
663 * that it is "safer" not to re-architect the code to fix the above
664 * issue, hence this "hack." We may be better off to have a new
665 * command with better syntax for configuring network interface
668 if (!scan_netmask
&& afp
->af_af
== AF_INET
) {
672 /* Only go thru the command list once to find the netmask. */
673 scan_netmask
= _B_TRUE
;
676 * Currently, if multiple netmask commands are specified, the
677 * last one will be used as the final netmask. So we need
678 * to scan the whole list to preserve this behavior.
680 for (largc
= argc
, largv
= argv
; largc
> 0; largc
--, largv
++) {
681 if (strcmp(*largv
, NETMASK_CMD
) == 0) {
685 if (strcmp(*largv
, "+") == 0) {
686 g_netmask_set
= G_NETMASK_PENDING
;
688 in_getaddr(*largv
, (struct sockaddr
*)
690 g_netmask_set
= G_NETMASK_SET
;
692 /* Continue the scan. */
702 (void) printf("ifconfig: argv %s\n", *argv
);
704 found_cmd
= _B_FALSE
;
705 for (p
= cmds
; p
->c_func
; p
++) {
707 if (strcmp(*argv
, p
->c_name
) == 0) {
709 * indicate that the command was
710 * found and check to see if
711 * the address family is valid
714 if (p
->c_af
== AF_ANY
||
719 if (p
->c_af
== AF_ANY
||
725 * If we found the keyword, but the address family
726 * did not match spit out an error
728 if (found_cmd
&& p
->c_name
== 0) {
729 (void) fprintf(stderr
, "ifconfig: Operation %s not"
730 " supported for %s\n", *argv
, afp
->af_name
);
734 * else (no keyword found), we assume it's an address
737 if (setaddr
&& ipaddr
!= NULL
) {
739 * We must have already filled in a source address in
740 * `ipaddr' and we now got a destination address.
741 * Fill it in `ipaddr' and call libipadm to create
742 * the static address.
744 if (p
->c_name
== 0) {
745 istatus
= ipadm_set_dst_addr(ipaddr
, *argv
,
746 (p
->c_af
== AF_ANY
? AF_UNSPEC
: af
));
747 if (istatus
!= IPADM_SUCCESS
) {
748 ipadmerr_exit(istatus
, "could not "
749 "set destination address");
752 * finished processing dstaddr, so reset setaddr
757 * Both source and destination address are in `ipaddr'.
758 * Add the address by calling libipadm.
760 istatus
= ipadm_create_addr(iph
, ipaddr
,
762 if (istatus
!= IPADM_SUCCESS
)
764 ipadm_destroy_addrobj(ipaddr
);
766 setaddr_done
= _B_TRUE
;
767 if (p
->c_name
== 0) {
768 /* move parser along */
773 if (p
->c_name
== 0 && setaddr_done
) {
775 * catch odd commands like
776 * "ifconfig <intf> addr1 addr2 addr3 addr4 up"
778 (void) fprintf(stderr
, "%s",
779 "ifconfig: cannot configure more than two "
780 "addresses in one command\n");
784 if (p
->c_af
== AF_INET6
) {
787 if (p
->c_parameter
== NEXTARG
||
788 p
->c_parameter
== OPTARG
) {
790 if (argc
== 0 && p
->c_parameter
== NEXTARG
) {
791 (void) fprintf(stderr
,
792 "ifconfig: no argument for %s\n",
798 * Call the function if:
800 * there's no address family
803 * we don't know the address yet
804 * (because we were called from
807 * there is a restriction AND
808 * the address families match
810 if ((p
->c_af
== AF_ANY
) ||
812 (ifa
->ifa_addr
->sa_family
== p
->c_af
)) {
813 ret
= (*p
->c_func
)(*argv
, p
->c_parameter
);
815 * If c_func failed and we should
816 * abort processing for this
817 * interface on failure, return
818 * now rather than going on to
819 * process other commands for
820 * the same interface.
822 if (ret
!= 0 && p
->c_abortonfail
)
829 if (setaddr
&& ipaddr
!= NULL
) {
831 * Only the source address was provided, which was already
832 * set in `ipaddr'. Add the address by calling libipadm.
834 istatus
= ipadm_create_addr(iph
, ipaddr
, IPADM_OPT_ACTIVE
);
835 if (istatus
!= IPADM_SUCCESS
)
837 ipadm_destroy_addrobj(ipaddr
);
839 setaddr_done
= _B_TRUE
;
842 /* Check to see if there's a security hole in the tunnel setup. */
843 if (ipsec_policy_set
&& !ipsec_auth_covered
) {
844 (void) fprintf(stderr
, "ifconfig: WARNING: tunnel with only "
845 "ESP and no authentication.\n");
850 (void) fprintf(stderr
, "ifconfig: could not create address:% s\n",
851 ipadm_status2str(istatus
));
852 /* Remove the newly created logical interface. */
853 if (strcmp(name
, origname
) != 0) {
854 assert(strchr(name
, ':') != NULL
);
855 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
856 (void) ioctl(s
, SIOCLIFREMOVEIF
, (caddr_t
)&lifr
);
863 setdebugflag(char *val
, int64_t arg
)
871 setverboseflag(char *val
, int64_t arg
)
878 * This function fills in the given lifreq's lifr_addr field based on
882 set_mask_lifreq(struct lifreq
*lifr
, struct sockaddr_storage
*addr
,
883 struct sockaddr_storage
*mask
)
885 assert(addr
!= NULL
);
886 assert(mask
!= NULL
);
888 switch (g_netmask_set
) {
890 lifr
->lifr_addr
= g_netmask
;
893 case G_NETMASK_PENDING
:
895 * "+" is used as the argument to "netmask" command. Query
896 * the database on the correct netmask based on the address to
899 assert(afp
->af_af
== AF_INET
);
901 if (!in_getmask((struct sockaddr_in
*)&g_netmask
, _B_TRUE
)) {
902 lifr
->lifr_addr
= *mask
;
903 g_netmask_set
= G_NETMASK_NIL
;
905 lifr
->lifr_addr
= g_netmask
;
906 g_netmask_set
= G_NETMASK_SET
;
912 lifr
->lifr_addr
= *mask
;
918 * Set the interface address. Handles <addr>, <addr>/<n> as well as /<n>
919 * syntax for setting the address, the address plus netmask, and just
920 * the netmask respectively.
924 setifaddr(char *addr
, int64_t param
)
926 ipadm_status_t istatus
;
929 struct sockaddr_storage laddr
;
930 struct sockaddr_storage netmask
;
931 struct sockaddr_in6
*sin6
;
932 struct sockaddr_in
*sin
;
933 struct sockaddr_storage sav_netmask
;
934 char cidraddr
[BUFSIZ
];
937 return (setifprefixlen(addr
, 0));
939 (*afp
->af_getaddr
)(addr
, (struct sockaddr
*)&laddr
, &prefixlen
);
941 (void) memset(&netmask
, 0, sizeof (netmask
));
942 netmask
.ss_family
= afp
->af_af
;
945 /* Nothing there - ok */
948 (void) fprintf(stderr
, "ifconfig: Bad prefix length in %s\n",
952 if (afp
->af_af
== AF_INET6
) {
953 sin6
= (struct sockaddr_in6
*)&netmask
;
954 if (!in_prefixlentomask(prefixlen
, IPV6_ABITS
,
955 (uchar_t
*)&sin6
->sin6_addr
)) {
956 (void) fprintf(stderr
, "ifconfig: "
957 "Bad prefix length: %d\n",
962 sin
= (struct sockaddr_in
*)&netmask
;
963 if (!in_prefixlentomask(prefixlen
, IP_ABITS
,
964 (uchar_t
*)&sin
->sin_addr
)) {
965 (void) fprintf(stderr
, "ifconfig: "
966 "Bad prefix length: %d\n",
972 * Just in case of funny setting of both prefix and netmask,
973 * prefix should override the netmask command.
975 g_netmask_set
= G_NETMASK_NIL
;
980 * Check and see if any "netmask" command is used and perform the
981 * necessary operation.
983 set_mask_lifreq(&lifr
, &laddr
, &netmask
);
985 /* This check is temporary until libipadm supports IPMP interfaces. */
986 if (ifconfig_use_libipadm(s
, name
)) {
987 char addrstr
[INET6_ADDRSTRLEN
];
990 sin
= (struct sockaddr_in
*)&laddr
;
991 (void) inet_ntop(AF_INET
, &sin
->sin_addr
, addrstr
,
994 sin6
= (struct sockaddr_in6
*)&laddr
;
995 (void) inet_ntop(AF_INET6
, &sin6
->sin6_addr
, addrstr
,
998 istatus
= ipadm_create_addrobj(IPADM_ADDR_STATIC
, name
,
1000 if (istatus
!= IPADM_SUCCESS
)
1001 ipadmerr_exit(istatus
, "setifaddr");
1004 * lifr.lifr_addr, which is updated by set_mask_lifreq()
1005 * will contain the right mask to use.
1007 prefixlen
= mask2plen((struct sockaddr
*)&lifr
.lifr_addr
);
1008 (void) snprintf(cidraddr
, sizeof (cidraddr
), "%s/%d",
1009 addrstr
, prefixlen
);
1011 istatus
= ipadm_set_addr(ipaddr
, cidraddr
, af
);
1012 if (istatus
!= IPADM_SUCCESS
)
1013 ipadmerr_exit(istatus
, "could not set address");
1015 * let parser know we got a source.
1016 * Next address, if given, should be dest
1021 * address will be set by the parser after nextarg has
1027 /* Tell parser that an address was set */
1029 /* save copy of netmask to restore in case of error */
1030 (void) strncpy(lifr1
.lifr_name
, name
, sizeof (lifr1
.lifr_name
));
1031 if (ioctl(s
, SIOCGLIFNETMASK
, (caddr_t
)&lifr1
) < 0)
1032 Perror0_exit("SIOCGLIFNETMASK");
1033 sav_netmask
= lifr1
.lifr_addr
;
1036 * If setting the address and not the mask, clear any existing mask
1037 * and the kernel will then assign the default (netmask has been set
1038 * to 0 in this case). If setting both (either by using a prefix or
1039 * using the netmask command), set the mask first, so the address will
1040 * be interpreted correctly.
1042 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1043 /* lifr.lifr_addr already contains netmask from set_mask_lifreq() */
1044 if (ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
) < 0)
1045 Perror0_exit("SIOCSLIFNETMASK");
1048 char abuf
[INET6_ADDRSTRLEN
];
1049 void *addr
= (afp
->af_af
== AF_INET
) ?
1050 (void *)&((struct sockaddr_in
*)&laddr
)->sin_addr
:
1051 (void *)&((struct sockaddr_in6
*)&laddr
)->sin6_addr
;
1053 (void) printf("Setting %s af %d addr %s\n",
1054 lifr
.lifr_name
, afp
->af_af
,
1055 inet_ntop(afp
->af_af
, addr
, abuf
, sizeof (abuf
)));
1057 lifr
.lifr_addr
= laddr
;
1058 lifr
.lifr_addr
.ss_family
= afp
->af_af
;
1059 if (ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
) < 0) {
1061 * Restore the netmask
1065 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1066 lifr
.lifr_addr
= sav_netmask
;
1067 (void) ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
);
1069 Perror0_exit("SIOCSLIFADDR");
1076 * The following functions are stolen from the ipseckey(1m) program.
1077 * Perhaps they should be somewhere common, but for now, we just maintain
1078 * two versions. We do this because of the different semantics for which
1079 * algorithms we select ("requested" for ifconfig vs. "actual" for key).
1089 rc
= strtoul(num
, &end
, 0);
1090 if (errno
!= 0 || end
== num
|| *end
!= '\0') {
1098 * Parse and reverse parse possible algorithm values, include numbers.
1099 * Mostly stolen from ipseckey.c. See the comments above parsenum() for why
1100 * this isn't common to ipseckey.c.
1102 * NOTE: Static buffer in this function for the return value. Since ifconfig
1103 * isn't multithreaded, this isn't a huge problem.
1106 #define NBUF_SIZE 20 /* Enough to print a large integer. */
1109 rparsealg(uint8_t alg_value
, int proto_num
)
1111 struct ipsecalgent
*alg
;
1112 static char numprint
[128]; /* Enough to hold an algorithm name. */
1115 * Special cases for "any" and "none"
1116 * The kernel needs to be able to distinguish between "any"
1117 * and "none" and the APIs are underdefined in this area for auth.
1119 if (proto_num
== IPSEC_PROTO_AH
) {
1120 if (alg_value
== SADB_AALG_NONE
)
1122 if (alg_value
== SADB_AALG_ANY
)
1126 alg
= getipsecalgbynum(alg_value
, proto_num
, NULL
);
1128 (void) strlcpy(numprint
, alg
->a_names
[0], sizeof (numprint
));
1129 freeipsecalgent(alg
);
1131 (void) snprintf(numprint
, sizeof (numprint
), "%d", alg_value
);
1138 parsealg(char *algname
, int proto_num
)
1140 struct ipsecalgent
*alg
;
1143 if (algname
== NULL
) {
1144 (void) fprintf(stderr
, "ifconfig: Unexpected end of command "
1150 * Special-case "none" and "any".
1151 * Use strcasecmp because its length is bounded.
1153 if (strcasecmp("none", algname
) == 0) {
1154 return ((proto_num
== IPSEC_PROTO_ESP
) ?
1155 NO_ESP_EALG
: NO_ESP_AALG
);
1157 if ((strcasecmp("any", algname
) == 0) && (proto_num
== IPSEC_PROTO_AH
))
1158 return (SADB_AALG_ANY
);
1160 alg
= getipsecalgbyname(algname
, proto_num
, NULL
);
1162 invalue
= alg
->a_alg_num
;
1163 freeipsecalgent(alg
);
1164 return ((uint_t
)invalue
);
1168 * Since algorithms can be loaded during kernel run-time, check for
1169 * numeric algorithm values too.
1171 invalue
= parsenum(algname
);
1172 if ((invalue
& (ulong_t
)0xff) == invalue
)
1173 return ((uint_t
)invalue
);
1175 (void) fprintf(stderr
, "ifconfig: %s algorithm type %s unknown.\n",
1176 (proto_num
== IPSEC_PROTO_ESP
) ?
1177 "Encryption" : "Authentication", algname
);
1183 * Actual ifconfig functions to set tunnel security properties.
1186 enum ipsec_alg_type
{ ESP_ENCR_ALG
= 1, ESP_AUTH_ALG
, AH_AUTH_ALG
};
1189 set_tun_algs(int which_alg
, int alg
)
1191 boolean_t encr_alg_set
= _B_FALSE
;
1192 iptun_params_t params
;
1193 dladm_status_t status
;
1196 if ((status
= ifconfig_dladm_open(name
, DATALINK_CLASS_IPTUN
,
1197 ¶ms
.iptun_param_linkid
)) != DLADM_STATUS_OK
)
1200 status
= dladm_iptun_getparams(dlh
, ¶ms
, DLADM_OPT_ACTIVE
);
1201 if (status
!= DLADM_STATUS_OK
)
1204 ipsr
= ¶ms
.iptun_param_secinfo
;
1207 * If I'm just starting off this ifconfig, I want a clean slate,
1208 * otherwise, I've captured the current tunnel security settings.
1209 * In the case of continuation, I merely add to the settings.
1211 if (!(params
.iptun_param_flags
& IPTUN_PARAM_SECINFO
))
1212 (void) memset(ipsr
, 0, sizeof (*ipsr
));
1214 /* We're only modifying the IPsec information */
1215 params
.iptun_param_flags
= IPTUN_PARAM_SECINFO
;
1217 switch (which_alg
) {
1219 if (alg
== NO_ESP_EALG
) {
1220 if (ipsr
->ipsr_esp_auth_alg
== SADB_AALG_NONE
)
1221 ipsr
->ipsr_esp_req
= 0;
1222 ipsr
->ipsr_esp_alg
= SADB_EALG_NONE
;
1224 /* Let the user specify NULL encryption implicitly. */
1225 if (ipsr
->ipsr_esp_auth_alg
!= SADB_AALG_NONE
) {
1226 encr_alg_set
= _B_TRUE
;
1227 ipsr
->ipsr_esp_alg
= SADB_EALG_NULL
;
1230 encr_alg_set
= _B_TRUE
;
1231 ipsr
->ipsr_esp_req
=
1232 IPSEC_PREF_REQUIRED
| IPSEC_PREF_UNIQUE
;
1233 ipsr
->ipsr_esp_alg
= alg
;
1237 if (alg
== NO_ESP_AALG
) {
1238 if ((ipsr
->ipsr_esp_alg
== SADB_EALG_NONE
||
1239 ipsr
->ipsr_esp_alg
== SADB_EALG_NULL
) &&
1241 ipsr
->ipsr_esp_req
= 0;
1242 ipsr
->ipsr_esp_auth_alg
= SADB_AALG_NONE
;
1244 ipsr
->ipsr_esp_req
=
1245 IPSEC_PREF_REQUIRED
| IPSEC_PREF_UNIQUE
;
1246 ipsr
->ipsr_esp_auth_alg
= alg
;
1248 /* Let the user specify NULL encryption implicitly. */
1249 if (ipsr
->ipsr_esp_alg
== SADB_EALG_NONE
&&
1251 ipsr
->ipsr_esp_alg
= SADB_EALG_NULL
;
1255 if (alg
== NO_AH_AALG
) {
1256 ipsr
->ipsr_ah_req
= 0;
1257 ipsr
->ipsr_auth_alg
= SADB_AALG_NONE
;
1260 IPSEC_PREF_REQUIRED
| IPSEC_PREF_UNIQUE
;
1261 ipsr
->ipsr_auth_alg
= alg
;
1264 /* Will never hit DEFAULT */
1267 status
= dladm_iptun_modify(dlh
, ¶ms
, DLADM_OPT_ACTIVE
);
1270 if (status
!= DLADM_STATUS_OK
)
1271 dladmerr_exit(status
, name
);
1273 ipsec_policy_set
= _B_TRUE
;
1274 if ((ipsr
->ipsr_esp_req
!= 0 &&
1275 ipsr
->ipsr_esp_auth_alg
!= SADB_AALG_NONE
) ||
1276 (ipsr
->ipsr_ah_req
!= 0 &&
1277 ipsr
->ipsr_auth_alg
!= SADB_AALG_NONE
))
1278 ipsec_auth_covered
= _B_TRUE
;
1285 set_tun_esp_encr_alg(char *addr
, int64_t param
)
1287 return (set_tun_algs(ESP_ENCR_ALG
,
1288 parsealg(addr
, IPSEC_PROTO_ESP
)));
1293 set_tun_esp_auth_alg(char *addr
, int64_t param
)
1295 return (set_tun_algs(ESP_AUTH_ALG
,
1296 parsealg(addr
, IPSEC_PROTO_AH
)));
1301 set_tun_ah_alg(char *addr
, int64_t param
)
1303 return (set_tun_algs(AH_AUTH_ALG
,
1304 parsealg(addr
, IPSEC_PROTO_AH
)));
1309 setifrevarp(char *arg
, int64_t param
)
1311 struct sockaddr_in laddr
;
1313 if (afp
->af_af
== AF_INET6
) {
1314 (void) fprintf(stderr
,
1315 "ifconfig: revarp not possible on IPv6 interface %s\n",
1319 if (doifrevarp(name
, &laddr
)) {
1320 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1321 laddr
.sin_family
= AF_INET
;
1322 (void) memcpy(&lifr
.lifr_addr
, &laddr
, sizeof (laddr
));
1323 if (ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
) < 0)
1324 Perror0_exit("SIOCSLIFADDR");
1331 setifsubnet(char *addr
, int64_t param
)
1334 struct sockaddr_storage subnet
;
1336 (*afp
->af_getaddr
)(addr
, &subnet
, &prefixlen
);
1338 switch (prefixlen
) {
1340 (void) fprintf(stderr
,
1341 "ifconfig: Missing prefix length in subnet %s\n", addr
);
1345 (void) fprintf(stderr
,
1346 "ifconfig: Bad prefix length in %s\n", addr
);
1352 lifr
.lifr_addr
= subnet
;
1353 lifr
.lifr_addrlen
= prefixlen
;
1354 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1355 if (ioctl(s
, SIOCSLIFSUBNET
, (caddr_t
)&lifr
) < 0)
1356 Perror0_exit("SIOCSLIFSUBNET");
1363 setifnetmask(char *addr
, int64_t param
)
1365 struct sockaddr_in netmask
;
1367 assert(afp
->af_af
!= AF_INET6
);
1369 if (strcmp(addr
, "+") == 0) {
1370 if (!in_getmask(&netmask
, _B_FALSE
))
1372 (void) printf("Setting netmask of %s to %s\n", name
,
1373 inet_ntoa(netmask
.sin_addr
));
1375 in_getaddr(addr
, (struct sockaddr
*)&netmask
, NULL
);
1377 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1378 (void) memcpy(&lifr
.lifr_addr
, &netmask
, sizeof (netmask
));
1379 if (ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
) < 0)
1380 Perror0_exit("SIOCSLIFNETMASK");
1385 * Parse '/<n>' as a netmask.
1389 setifprefixlen(char *addr
, int64_t param
)
1392 int af
= afp
->af_af
;
1394 prefixlen
= in_getprefixlen(addr
, _B_TRUE
,
1395 (af
== AF_INET
) ? IP_ABITS
: IPV6_ABITS
);
1396 if (prefixlen
< 0) {
1397 (void) fprintf(stderr
,
1398 "ifconfig: Bad prefix length in %s\n", addr
);
1401 (void) memset(&lifr
.lifr_addr
, 0, sizeof (lifr
.lifr_addr
));
1402 lifr
.lifr_addr
.ss_family
= af
;
1403 if (af
== AF_INET6
) {
1404 struct sockaddr_in6
*sin6
;
1406 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
1407 if (!in_prefixlentomask(prefixlen
, IPV6_ABITS
,
1408 (uchar_t
*)&sin6
->sin6_addr
)) {
1409 (void) fprintf(stderr
, "ifconfig: "
1410 "Bad prefix length: %d\n",
1414 } else if (af
== AF_INET
) {
1415 struct sockaddr_in
*sin
;
1417 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
1418 if (!in_prefixlentomask(prefixlen
, IP_ABITS
,
1419 (uchar_t
*)&sin
->sin_addr
)) {
1420 (void) fprintf(stderr
, "ifconfig: "
1421 "Bad prefix length: %d\n",
1426 (void) fprintf(stderr
, "ifconfig: setting prefix only supported"
1427 " for address family inet or inet6\n");
1430 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1431 if (ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
) < 0)
1432 Perror0_exit("SIOCSLIFNETMASK");
1438 setifbroadaddr(char *addr
, int64_t param
)
1440 struct sockaddr_in broadaddr
;
1442 assert(afp
->af_af
!= AF_INET6
);
1444 if (strcmp(addr
, "+") == 0) {
1446 * This doesn't set the broadcast address at all. Rather, it
1447 * gets, then sets the interface's address, relying on the fact
1448 * that resetting the address will reset the broadcast address.
1450 (void) strncpy(lifr
.lifr_name
, name
,
1451 sizeof (lifr
.lifr_name
));
1452 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
1453 if (errno
!= EADDRNOTAVAIL
)
1454 Perror0_exit("SIOCGLIFADDR");
1457 if (ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
) < 0)
1458 Perror0_exit("SIOCGLIFADDR");
1462 in_getaddr(addr
, (struct sockaddr
*)&broadaddr
, NULL
);
1464 (void) memcpy(&lifr
.lifr_addr
, &broadaddr
, sizeof (broadaddr
));
1465 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1466 if (ioctl(s
, SIOCSLIFBRDADDR
, (caddr_t
)&lifr
) < 0)
1467 Perror0_exit("SIOCSLIFBRDADDR");
1472 * set interface destination address
1476 setifdstaddr(char *addr
, int64_t param
)
1478 (*afp
->af_getaddr
)(addr
, (struct sockaddr
*)&lifr
.lifr_addr
, NULL
);
1479 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1480 if (ioctl(s
, SIOCSLIFDSTADDR
, (caddr_t
)&lifr
) < 0)
1481 Perror0_exit("setifdstaddr: SIOCSLIFDSTADDR");
1487 setifflags(char *val
, int64_t value
)
1489 struct lifreq lifrl
; /* local lifreq struct */
1490 boolean_t bringup
= _B_FALSE
;
1492 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1493 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0)
1494 Perror0_exit("setifflags: SIOCGLIFFLAGS");
1499 if ((value
& IFF_NOFAILOVER
) && (lifr
.lifr_flags
& IFF_UP
)) {
1501 * The kernel does not allow administratively up test
1502 * addresses to be converted to data addresses. Bring
1503 * the address down first, then bring it up after it's
1504 * been converted to a data address.
1506 lifr
.lifr_flags
&= ~IFF_UP
;
1507 (void) ioctl(s
, SIOCSLIFFLAGS
, (caddr_t
)&lifr
);
1511 lifr
.lifr_flags
&= ~value
;
1512 if ((value
& (IFF_UP
| IFF_NOFAILOVER
)) &&
1513 (lifr
.lifr_flags
& IFF_DUPLICATE
)) {
1515 * If the user is trying to mark an interface with a
1516 * duplicate address as "down," or convert a duplicate
1517 * test address to a data address, then fetch the
1518 * address and set it. This will cause IP to clear
1519 * the IFF_DUPLICATE flag and stop the automatic
1522 value
= lifr
.lifr_flags
;
1523 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) >= 0)
1524 (void) ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
);
1525 lifr
.lifr_flags
= value
;
1528 lifr
.lifr_flags
|= value
;
1532 * If we're about to bring up an underlying physical IPv6 interface in
1533 * an IPMP group, ensure the IPv6 IPMP interface is also up. This is
1534 * for backward compatibility with legacy configurations in which
1535 * there are no explicit hostname files for IPMP interfaces. (For
1536 * IPv4, this is automatically handled by the kernel when migrating
1537 * the underlying interface's data address to the IPMP interface.)
1539 (void) strlcpy(lifrl
.lifr_name
, name
, LIFNAMSIZ
);
1541 if (lifnum(lifr
.lifr_name
) == 0 &&
1542 (lifr
.lifr_flags
& (IFF_UP
|IFF_IPV6
)) == (IFF_UP
|IFF_IPV6
) &&
1543 ioctl(s
, SIOCGLIFGROUPNAME
, &lifrl
) == 0 &&
1544 lifrl
.lifr_groupname
[0] != '\0') {
1545 lifgroupinfo_t lifgr
;
1547 (void) strlcpy(lifgr
.gi_grname
, lifrl
.lifr_groupname
,
1549 if (ioctl(s
, SIOCGLIFGROUPINFO
, &lifgr
) == -1)
1550 Perror0_exit("setifflags: SIOCGLIFGROUPINFO");
1552 (void) strlcpy(lifrl
.lifr_name
, lifgr
.gi_grifname
, LIFNAMSIZ
);
1553 if (ioctl(s
, SIOCGLIFFLAGS
, &lifrl
) == -1)
1554 Perror0_exit("setifflags: SIOCGLIFFLAGS");
1555 if (!(lifrl
.lifr_flags
& IFF_UP
)) {
1556 lifrl
.lifr_flags
|= IFF_UP
;
1557 if (ioctl(s
, SIOCSLIFFLAGS
, &lifrl
) == -1)
1558 Perror0_exit("setifflags: SIOCSLIFFLAGS");
1562 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1563 if (ioctl(s
, SIOCSLIFFLAGS
, (caddr_t
)&lifr
) < 0)
1564 Perror0_exit("setifflags: SIOCSLIFFLAGS");
1567 lifr
.lifr_flags
|= IFF_UP
;
1568 if (ioctl(s
, SIOCSLIFFLAGS
, (caddr_t
)&lifr
) < 0)
1569 Perror0_exit("setifflags: SIOCSLIFFLAGS IFF_UP");
1577 setifmetric(char *val
, int64_t param
)
1579 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1580 lifr
.lifr_metric
= atoi(val
);
1581 if (ioctl(s
, SIOCSLIFMETRIC
, (caddr_t
)&lifr
) < 0)
1582 Perror0_exit("setifmetric: SIOCSLIFMETRIC");
1588 setifmtu(char *val
, int64_t param
)
1590 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1591 lifr
.lifr_mtu
= atoi(val
);
1592 if (ioctl(s
, SIOCSLIFMTU
, (caddr_t
)&lifr
) < 0)
1593 Perror0_exit("setifmtu: SIOCSLIFMTU");
1599 setifindex(char *val
, int64_t param
)
1601 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1602 lifr
.lifr_index
= atoi(val
);
1603 if (ioctl(s
, SIOCSLIFINDEX
, (caddr_t
)&lifr
) < 0)
1604 Perror0_exit("setifindex: SIOCSLIFINDEX");
1610 notifycb(dlpi_handle_t dh
, dlpi_notifyinfo_t
*dnip
, void *arg
)
1616 setifether(char *addr
, int64_t param
)
1621 ifaddrlistx_t
*ifaddrp
, *ifaddrs
= NULL
;
1627 print_ifether(name
);
1632 * if the IP interface in the arguments is a logical
1633 * interface, exit with an error now.
1635 if (strchr(name
, ':') != NULL
) {
1636 (void) fprintf(stderr
, "ifconfig: cannot change"
1637 " ethernet address of a logical interface\n");
1641 if ((hwaddr
= _link_aton(addr
, &hwaddrlen
)) == NULL
) {
1642 if (hwaddrlen
== -1)
1643 (void) fprintf(stderr
,
1644 "ifconfig: bad ethernet address\n");
1646 (void) fprintf(stderr
, "ifconfig: malloc() failed\n");
1650 if ((retval
= dlpi_open(name
, &dh
, 0)) != DLPI_SUCCESS
)
1651 Perrdlpi_exit("cannot dlpi_open() link", name
, retval
);
1653 retval
= dlpi_enabnotify(dh
, DL_NOTE_PHYS_ADDR
, notifycb
, NULL
, &id
);
1654 if (retval
== DLPI_SUCCESS
) {
1655 (void) dlpi_disabnotify(dh
, id
, NULL
);
1658 * This link does not support DL_NOTE_PHYS_ADDR: bring down
1659 * all of the addresses to flush the old hardware address
1660 * information out of IP.
1662 * NOTE: Skipping this when DL_NOTE_PHYS_ADDR is supported is
1663 * more than an optimization: in.mpathd will set IFF_OFFLINE
1664 * if it's notified and the new address is a duplicate of
1665 * another in the group -- but the flags manipulation in
1666 * ifaddr_{down,up}() cannot be atomic and thus might clobber
1667 * IFF_OFFLINE, confusing in.mpathd.
1669 if (ifaddrlistx(name
, IFF_UP
, 0, &ifaddrs
) == -1)
1670 Perror2_exit(name
, "cannot get address list");
1673 for (; ifaddrp
!= NULL
; ifaddrp
= ifaddrp
->ia_next
) {
1674 if (!ifaddr_down(ifaddrp
)) {
1675 Perror2_exit(ifaddrp
->ia_name
,
1676 "cannot bring down");
1682 * Change the hardware address.
1684 retval
= dlpi_set_physaddr(dh
, DL_CURR_PHYS_ADDR
, hwaddr
, hwaddrlen
);
1685 if (retval
!= DLPI_SUCCESS
) {
1686 (void) fprintf(stderr
,
1687 "ifconfig: failed setting mac address on %s\n", name
);
1692 * If any addresses were brought down before changing the hardware
1693 * address, bring them up again.
1695 for (ifaddrp
= ifaddrs
; ifaddrp
!= NULL
; ifaddrp
= ifaddrp
->ia_next
) {
1696 if (!ifaddr_up(ifaddrp
))
1697 Perror2_exit(ifaddrp
->ia_name
, "cannot bring up");
1699 ifaddrlistx_free(ifaddrs
);
1705 * Print an interface's Ethernet address, if it has one.
1708 print_ifether(const char *ifname
)
1712 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1714 fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
1715 if (fd
== -1 || ioctl(fd
, SIOCGLIFFLAGS
, &lifr
) == -1) {
1717 * It's possible the interface is only configured for
1718 * IPv6; check again with AF_INET6.
1721 fd
= socket(AF_INET6
, SOCK_DGRAM
, 0);
1722 if (fd
== -1 || ioctl(fd
, SIOCGLIFFLAGS
, &lifr
) == -1) {
1729 /* VNI and IPMP interfaces don't have MAC addresses */
1730 if (lifr
.lifr_flags
& (IFF_VIRTUAL
|IFF_IPMP
))
1733 /* IP tunnels also don't have Ethernet-like MAC addresses */
1734 if (ifconfig_dladm_open(ifname
, DATALINK_CLASS_IPTUN
, NULL
) ==
1738 dlpi_print_address(ifname
);
1742 * static int find_all_interfaces(struct lifconf *lifcp, char **buf,
1743 * int64_t lifc_flags)
1745 * It finds all active data links.
1747 * It takes in input a pointer to struct lifconf to receive interfaces
1748 * informations, a **char to hold allocated buffer, and a lifc_flags.
1755 find_all_interfaces(struct lifconf
*lifcp
, char **buf
, int64_t lifc_flags
)
1760 struct lifreq
*lifrp
;
1761 dladm_status_t status
;
1764 status
= ifconfig_dladm_open(NULL
, 0, NULL
);
1765 if (status
!= DLADM_STATUS_OK
)
1766 dladmerr_exit(status
, "unable to open dladm handle");
1769 (void) dlpi_walk(ni_entry
, dlh
, 0);
1771 /* Now, translate the linked list into a struct lifreq buffer */
1773 lifcp
->lifc_family
= AF_UNSPEC
;
1774 lifcp
->lifc_flags
= lifc_flags
;
1775 lifcp
->lifc_len
= 0;
1776 lifcp
->lifc_buf
= NULL
;
1780 bufsize
= num_ni
* sizeof (struct lifreq
);
1781 if ((*buf
= malloc(bufsize
)) == NULL
)
1782 Perror0_exit("find_all_interfaces: malloc failed");
1784 lifcp
->lifc_family
= AF_UNSPEC
;
1785 lifcp
->lifc_flags
= lifc_flags
;
1786 lifcp
->lifc_len
= bufsize
;
1787 lifcp
->lifc_buf
= *buf
;
1789 for (n
= 0, lifrp
= lifcp
->lifc_req
; n
< num_ni
; n
++, lifrp
++) {
1791 (void) strncpy(lifrp
->lifr_name
, nip
->ni_name
,
1792 sizeof (lifr
.lifr_name
));
1793 ni_list
= nip
->ni_next
;
1800 * Create the next unused logical interface using the original name
1801 * and assign the address (and mask if '/<n>' is part of the address).
1802 * Use the new logical interface for subsequent subcommands by updating
1803 * the name variable.
1805 * This allows syntax like:
1806 * ifconfig le0 addif 109.106.86.130 netmask + up \
1807 * addif 109.106.86.131 netmask + up
1811 addif(char *str
, int64_t param
)
1814 struct sockaddr_storage laddr
;
1815 struct sockaddr_storage mask
;
1816 struct sockaddr_in6
*sin6
;
1817 struct sockaddr_in
*sin
;
1818 ipadm_status_t istatus
;
1819 char cidraddr
[BUFSIZ
];
1820 char addrstr
[INET6_ADDRSTRLEN
];
1822 (void) strncpy(name
, origname
, sizeof (name
));
1824 if (strchr(name
, ':') != NULL
) {
1825 (void) fprintf(stderr
,
1826 "ifconfig: addif: bad physical interface name %s\n",
1832 * clear so parser will interpret next address as source followed
1836 (*afp
->af_getaddr
)(str
, (struct sockaddr
*)&laddr
, &prefixlen
);
1838 (void) memset(&mask
, 0, sizeof (mask
));
1839 mask
.ss_family
= afp
->af_af
;
1841 switch (prefixlen
) {
1843 /* Nothing there - ok */
1846 (void) fprintf(stderr
,
1847 "ifconfig: Bad prefix length in %s\n", str
);
1850 (void) memset(&mask
, 0, sizeof (mask
));
1851 mask
.ss_family
= afp
->af_af
;
1852 if (afp
->af_af
== AF_INET6
) {
1853 sin6
= (struct sockaddr_in6
*)&mask
;
1854 if (!in_prefixlentomask(prefixlen
, IPV6_ABITS
,
1855 (uchar_t
*)&sin6
->sin6_addr
)) {
1856 (void) fprintf(stderr
, "ifconfig: "
1857 "Bad prefix length: %d\n",
1862 sin
= (struct sockaddr_in
*)&mask
;
1863 if (!in_prefixlentomask(prefixlen
, IP_ABITS
,
1864 (uchar_t
*)&sin
->sin_addr
)) {
1865 (void) fprintf(stderr
, "ifconfig: "
1866 "Bad prefix length: %d\n",
1871 g_netmask_set
= G_NETMASK_NIL
;
1876 * This is a "hack" to get around the problem of SIOCLIFADDIF. The
1877 * problem is that this ioctl does not include the netmask when
1878 * adding a logical interface. This is the same problem described
1879 * in the ifconfig() comments. To get around this problem, we first
1880 * add the logical interface with a 0 address. After that, we set
1881 * the netmask if provided. Finally we set the interface address.
1883 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1884 (void) memset(&lifr
.lifr_addr
, 0, sizeof (lifr
.lifr_addr
));
1886 /* Note: no need to do DAD here since the interface isn't up yet. */
1888 if (ioctl(s
, SIOCLIFADDIF
, (caddr_t
)&lifr
) < 0)
1889 Perror0_exit("addif: SIOCLIFADDIF");
1891 (void) printf("Created new logical interface %s\n",
1893 (void) strncpy(name
, lifr
.lifr_name
, sizeof (name
));
1896 * Check and see if any "netmask" command is used and perform the
1897 * necessary operation.
1899 set_mask_lifreq(&lifr
, &laddr
, &mask
);
1901 /* This check is temporary until libipadm supports IPMP interfaces. */
1902 if (ifconfig_use_libipadm(s
, name
)) {
1904 * We added the logical interface above before calling
1905 * ipadm_create_addr(), because, with IPH_LEGACY, we need
1906 * to do an addif for `ifconfig ce0 addif <addr>' but not for
1907 * `ifconfig ce0 <addr>'. libipadm does not have a flag to
1908 * to differentiate between these two cases. To keep it simple,
1909 * we always create the logical interface and pass it to
1910 * libipadm instead of requiring libipadm to addif for some
1911 * cases and not do addif for other cases.
1913 istatus
= ipadm_create_addrobj(IPADM_ADDR_STATIC
, name
,
1915 if (istatus
!= IPADM_SUCCESS
)
1916 ipadmerr_exit(istatus
, "addif");
1918 if (af
== AF_INET
) {
1919 sin
= (struct sockaddr_in
*)&laddr
;
1920 (void) inet_ntop(AF_INET
, &sin
->sin_addr
, addrstr
,
1923 sin6
= (struct sockaddr_in6
*)&laddr
;
1924 (void) inet_ntop(AF_INET6
, &sin6
->sin6_addr
, addrstr
,
1928 * lifr.lifr_addr, which is updated by set_mask_lifreq()
1929 * will contain the right mask to use.
1931 prefixlen
= mask2plen((struct sockaddr
*)&lifr
.lifr_addr
);
1933 (void) snprintf(cidraddr
, sizeof (cidraddr
), "%s/%d",
1934 addrstr
, prefixlen
);
1936 istatus
= ipadm_set_addr(ipaddr
, cidraddr
, af
);
1938 if (istatus
!= IPADM_SUCCESS
)
1939 ipadmerr_exit(istatus
, "could not set address");
1942 * address will be set by the parser after nextarg
1949 * Only set the netmask if "netmask" command is used or a prefix is
1952 if (g_netmask_set
== G_NETMASK_SET
|| prefixlen
>= 0) {
1954 * lifr.lifr_addr already contains netmask from
1955 * set_mask_lifreq().
1957 if (ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
) < 0)
1958 Perror0_exit("addif: SIOCSLIFNETMASK");
1961 /* Finally, we set the interface address. */
1962 lifr
.lifr_addr
= laddr
;
1963 if (ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
) < 0)
1964 Perror0_exit("SIOCSLIFADDR");
1967 * let parser know we got a source.
1968 * Next address, if given, should be dest
1975 * Remove a logical interface based on its IP address. Unlike addif
1976 * there is no '/<n>' here.
1977 * Verifies that the interface is down before it is removed.
1981 removeif(char *str
, int64_t param
)
1983 struct sockaddr_storage laddr
;
1984 ipadm_status_t istatus
;
1985 ipadm_addr_info_t
*ainfo
, *ainfop
;
1987 if (strchr(name
, ':') != NULL
) {
1988 (void) fprintf(stderr
,
1989 "ifconfig: removeif: bad physical interface name %s\n",
1994 (*afp
->af_getaddr
)(str
, &laddr
, NULL
);
1997 * Following check is temporary until libipadm supports
2000 if (!ifconfig_use_libipadm(s
, name
))
2004 * Get all addresses and search this address among the active
2005 * addresses. If an address object was found, delete using
2006 * ipadm_delete_addr().
2008 istatus
= ipadm_addr_info(iph
, name
, &ainfo
, 0, LIFC_DEFAULT
);
2009 if (istatus
!= IPADM_SUCCESS
)
2010 ipadmerr_exit(istatus
, "removeif");
2012 for (ainfop
= ainfo
; ainfop
!= NULL
; ainfop
= IA_NEXT(ainfop
))
2014 (struct sockaddr_storage
*)ainfop
->ia_ifa
.ifa_addr
, &laddr
))
2017 if (ainfop
!= NULL
) {
2018 if (strchr(ainfop
->ia_ifa
.ifa_name
, ':') == NULL
) {
2019 (void) fprintf(stderr
,
2020 "ifconfig: removeif: cannot remove interface: %s\n",
2024 if (ainfop
->ia_aobjname
[0] != '\0') {
2025 istatus
= ipadm_delete_addr(iph
, ainfop
->ia_aobjname
,
2027 if (istatus
!= IPADM_SUCCESS
) {
2028 ipadmerr_exit(istatus
,
2029 "could not delete address");
2031 ipadm_free_addr_info(ainfo
);
2035 ipadm_free_addr_info(ainfo
);
2039 * An address object for this address was not found in ipadm.
2040 * Delete with SIOCLIFREMOVEIF.
2042 lifr
.lifr_addr
= laddr
;
2043 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2044 if (ioctl(s
, SIOCLIFREMOVEIF
, (caddr_t
)&lifr
) < 0) {
2045 if (errno
== EBUSY
) {
2046 /* This can only happen if ipif_id = 0 */
2047 (void) fprintf(stderr
,
2048 "ifconfig: removeif: cannot remove interface: %s\n",
2052 Perror0_exit("removeif: SIOCLIFREMOVEIF");
2058 * Set the address token for IPv6.
2062 setiftoken(char *addr
, int64_t param
)
2065 struct sockaddr_in6 token
;
2067 in6_getaddr(addr
, (struct sockaddr
*)&token
, &prefixlen
);
2068 switch (prefixlen
) {
2070 (void) fprintf(stderr
,
2071 "ifconfig: Missing prefix length in subnet %s\n", addr
);
2075 (void) fprintf(stderr
,
2076 "ifconfig: Bad prefix length in %s\n", addr
);
2081 (void) memcpy(&lifr
.lifr_addr
, &token
, sizeof (token
));
2082 lifr
.lifr_addrlen
= prefixlen
;
2083 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2084 if (ioctl(s
, SIOCSLIFTOKEN
, (caddr_t
)&lifr
) < 0) {
2085 Perror0_exit("setiftoken: SIOCSLIFTOKEN");
2092 setifgroupname(char *grname
, int64_t param
)
2094 lifgroupinfo_t lifgr
;
2095 struct lifreq lifrl
;
2096 ifaddrlistx_t
*ifaddrp
, *nextifaddrp
;
2097 ifaddrlistx_t
*ifaddrs
= NULL
, *downaddrs
= NULL
;
2101 (void) printf("Setting groupname %s on interface %s\n",
2105 (void) strlcpy(lifrl
.lifr_name
, name
, LIFNAMSIZ
);
2106 (void) strlcpy(lifrl
.lifr_groupname
, grname
, LIFGRNAMSIZ
);
2108 while (ioctl(s
, SIOCSLIFGROUPNAME
, &lifrl
) == -1) {
2112 * The group doesn't yet exist; create it and repeat.
2115 if (create_ipmp(grname
, af
, NULL
, _B_TRUE
) == -1) {
2116 if (errno
== EEXIST
)
2119 Perror2(grname
, "cannot create IPMP group");
2126 * The interface is already in another group; must
2127 * remove existing membership first.
2129 lifrl
.lifr_groupname
[0] = '\0';
2130 if (ioctl(s
, SIOCSLIFGROUPNAME
, &lifrl
) == -1) {
2131 Perror2(name
, "cannot remove existing "
2132 "IPMP group membership");
2135 (void) strlcpy(lifrl
.lifr_groupname
, grname
,
2141 * The group exists, but it's not configured with the
2142 * address families the interface needs. Since only
2143 * two address families are currently supported, just
2144 * configure the "other" address family. Note that we
2145 * may race with group deletion or creation by another
2146 * process (ENOENT or EEXIST); in such cases we repeat
2147 * our original SIOCSLIFGROUPNAME.
2149 (void) strlcpy(lifgr
.gi_grname
, grname
, LIFGRNAMSIZ
);
2150 if (ioctl(s
, SIOCGLIFGROUPINFO
, &lifgr
) == -1) {
2151 if (errno
== ENOENT
)
2154 Perror2(grname
, "SIOCGLIFGROUPINFO");
2158 af
= lifgr
.gi_v4
? AF_INET6
: AF_INET
;
2159 if (create_ipmp(grname
, af
, lifgr
.gi_grifname
,
2161 if (errno
== EEXIST
)
2164 Perror2(grname
, "cannot configure IPMP group");
2171 * Some addresses are in-use (or under control of DAD).
2172 * Bring them down and retry the group join operation.
2173 * We will bring them back up after the interface has
2174 * been placed in the group.
2176 if (ifaddrlistx(lifrl
.lifr_name
, IFF_UP
|IFF_DUPLICATE
,
2177 0, &ifaddrs
) == -1) {
2178 Perror2(grname
, "cannot get address list");
2183 for (; ifaddrp
!= NULL
; ifaddrp
= nextifaddrp
) {
2184 if (!ifaddr_down(ifaddrp
)) {
2188 nextifaddrp
= ifaddrp
->ia_next
;
2189 ifaddrp
->ia_next
= downaddrs
;
2190 downaddrs
= ifaddrp
;
2195 case EADDRNOTAVAIL
: {
2197 * Some data addresses are under application control.
2198 * For some of these (e.g., ADDRCONF), the application
2199 * should remove the address, in which case we retry a
2200 * few times (since the application's action is not
2201 * atomic with respect to us) before bailing out and
2202 * informing the user.
2204 int ntries
, nappaddr
= 0;
2205 const if_appflags_t
*iap
= if_appflags_tbl
;
2207 for (; iap
->ia_app
!= NULL
; iap
++) {
2210 if (ifaddrlistx(lifrl
.lifr_name
, iap
->ia_flag
,
2211 IFF_NOFAILOVER
, &ifaddrs
) == -1) {
2212 (void) fprintf(stderr
, "ifconfig: %s: "
2213 "cannot get data addresses managed "
2214 "by %s\n", lifrl
.lifr_name
,
2219 if (ifaddrs
== NULL
)
2222 ifaddrlistx_free(ifaddrs
);
2225 if (++ntries
< iap
->ia_tries
) {
2226 (void) poll(NULL
, 0, 100);
2230 (void) fprintf(stderr
, "ifconfig: cannot join "
2231 "IPMP group: %s has data addresses managed "
2232 "by %s\n", lifrl
.lifr_name
, iap
->ia_app
);
2240 Perror2(name
, "SIOCSLIFGROUPNAME");
2246 * If the interface being moved is under the control of `ipmgmtd(1M)'
2247 * dameon then we should inform the daemon about this move, so that
2248 * the daemon can delete the state associated with this interface.
2250 * This workaround is needed until the IPMP support in ipadm(1M).
2252 ipadm_if_move(iph
, name
);
2255 * If there were addresses that we had to bring down, it's time to
2256 * bring them up again. As part of bringing them up, the kernel will
2257 * automatically move them to the new IPMP interface.
2259 for (ifaddrp
= downaddrs
; ifaddrp
!= NULL
; ifaddrp
= ifaddrp
->ia_next
) {
2260 if (!ifaddr_up(ifaddrp
) && errno
!= ENXIO
) {
2261 (void) fprintf(stderr
, "ifconfig: cannot bring back up "
2262 "%s: %s\n", ifaddrp
->ia_name
, strerror(errno
));
2265 ifaddrlistx_free(downaddrs
);
2269 * Attempt to bring back up any interfaces that we downed.
2271 for (ifaddrp
= downaddrs
; ifaddrp
!= NULL
; ifaddrp
= ifaddrp
->ia_next
) {
2272 if (!ifaddr_up(ifaddrp
) && errno
!= ENXIO
) {
2273 (void) fprintf(stderr
, "ifconfig: cannot bring back up "
2274 "%s: %s\n", ifaddrp
->ia_name
, strerror(errno
));
2277 ifaddrlistx_free(downaddrs
);
2278 ifaddrlistx_free(ifaddrs
);
2281 * We'd return -1, but foreachinterface() doesn't propagate the error
2282 * into the exit status, so we're forced to explicitly exit().
2289 modcheck(const char *ifname
)
2291 (void) strlcpy(lifr
.lifr_name
, ifname
, sizeof (lifr
.lifr_name
));
2293 if (ioctl(s
, SIOCGLIFFLAGS
, &lifr
) < 0) {
2294 Perror0("SIOCGLIFFLAGS");
2298 if (lifr
.lifr_flags
& IFF_IPMP
) {
2299 (void) fprintf(stderr
, "ifconfig: %s: module operations not"
2300 " supported on IPMP interfaces\n", ifname
);
2303 if (lifr
.lifr_flags
& IFF_VIRTUAL
) {
2304 (void) fprintf(stderr
, "ifconfig: %s: module operations not"
2305 " supported on virtual IP interfaces\n", ifname
);
2312 * To list all the modules above a given network interface.
2316 modlist(char *null
, int64_t param
)
2324 struct str_list strlist
;
2328 * We'd return -1, but foreachinterface() doesn't propagate the error
2329 * into the exit status, so we're forced to explicitly exit().
2331 if (!modcheck(name
))
2334 if (ip_domux2fd(&muxfd
, &muxid_fd
, &ipfd_lowstr
, &arpfd_lowstr
,
2338 if ((num_mods
= ioctl(ipfd_lowstr
, I_LIST
, NULL
)) < 0) {
2339 Perror0("cannot I_LIST to get the number of modules");
2342 (void) printf("Listing (%d) modules above %s\n",
2346 strlist
.sl_nmods
= num_mods
;
2347 strlist
.sl_modlist
= malloc(sizeof (struct str_mlist
) *
2349 if (strlist
.sl_modlist
== NULL
) {
2350 Perror0("cannot malloc");
2352 if (ioctl(ipfd_lowstr
, I_LIST
, (caddr_t
)&strlist
) < 0) {
2353 Perror0("cannot I_LIST for module names");
2355 for (i
= 0; i
< strlist
.sl_nmods
; i
++) {
2356 (void) printf("%d %s\n", i
,
2357 strlist
.sl_modlist
[i
].l_name
);
2360 free(strlist
.sl_modlist
);
2363 return (ip_plink(muxfd
, muxid_fd
, ipfd_lowstr
, arpfd_lowstr
,
2367 #define MODINSERT_OP 'i'
2368 #define MODREMOVE_OP 'r'
2371 * To insert a module to the stream of the interface. It is just a
2372 * wrapper. The real function is modop().
2376 modinsert(char *arg
, int64_t param
)
2378 return (modop(arg
, MODINSERT_OP
));
2382 * To remove a module from the stream of the interface. It is just a
2383 * wrapper. The real function is modop().
2387 modremove(char *arg
, int64_t param
)
2389 return (modop(arg
, MODREMOVE_OP
));
2393 * Helper function for mod*() functions. It gets a fd to the lower IP
2394 * stream and I_PUNLINK's the lower stream. It also initializes the
2395 * global variable lifr.
2398 * int *muxfd: fd to /dev/udp{,6} for I_PLINK/I_PUNLINK
2399 * int *muxid_fd: fd to /dev/udp{,6} for LIFMUXID
2400 * int *ipfd_lowstr: fd to the lower IP stream.
2401 * int *arpfd_lowstr: fd to the lower ARP stream.
2404 * -1 if operation fails, 0 otherwise.
2406 * Please see the big block comment above ifplumb() for the logic of the
2410 ip_domux2fd(int *muxfd
, int *muxid_fd
, int *ipfd_lowstr
, int *arpfd_lowstr
,
2417 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2418 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0) {
2419 Perror0_exit("status: SIOCGLIFFLAGS");
2421 flags
= lifr
.lifr_flags
;
2422 if (flags
& IFF_IPV4
) {
2423 udp_dev_name
= UDP_DEV_NAME
;
2424 } else if (flags
& IFF_IPV6
) {
2425 udp_dev_name
= UDP6_DEV_NAME
;
2430 if ((*muxid_fd
= open(udp_dev_name
, O_RDWR
)) < 0) {
2431 Perror2("open", udp_dev_name
);
2434 if (ioctl(*muxid_fd
, SIOCGLIFMUXID
, (caddr_t
)&lifr
) < 0) {
2435 Perror2("SIOCGLIFMUXID", udp_dev_name
);
2439 (void) printf("ARP_muxid %d IP_muxid %d\n",
2440 lifr
.lifr_arp_muxid
, lifr
.lifr_ip_muxid
);
2444 * Use /dev/udp{,6} as the mux to avoid linkcycles.
2446 if (ipadm_open_arp_on_udp(udp_dev_name
, muxfd
) != IPADM_SUCCESS
)
2449 if (lifr
.lifr_arp_muxid
!= 0) {
2450 if ((*arpfd_lowstr
= ioctl(*muxfd
, _I_MUXID2FD
,
2451 lifr
.lifr_arp_muxid
)) < 0) {
2452 if ((errno
== EINVAL
) &&
2453 (flags
& (IFF_NOARP
| IFF_IPV6
))) {
2455 * Some plumbing utilities set the muxid to
2456 * -1 or some invalid value to signify that
2457 * there is no arp stream. Set the muxid to 0
2458 * before trying to unplumb the IP stream.
2459 * IP does not allow the IP stream to be
2460 * unplumbed if it sees a non-null arp muxid,
2461 * for consistency of IP-ARP streams.
2463 *orig_arpid
= lifr
.lifr_arp_muxid
;
2464 lifr
.lifr_arp_muxid
= 0;
2465 (void) ioctl(*muxid_fd
, SIOCSLIFMUXID
,
2469 Perror0("_I_MUXID2FD");
2472 } else if (ioctl(*muxfd
, I_PUNLINK
,
2473 lifr
.lifr_arp_muxid
) < 0) {
2474 Perror2("I_PUNLINK", udp_dev_name
);
2481 if ((*ipfd_lowstr
= ioctl(*muxfd
, _I_MUXID2FD
,
2482 lifr
.lifr_ip_muxid
)) < 0) {
2483 Perror0("_I_MUXID2FD");
2484 /* Undo any changes we made */
2485 if (*orig_arpid
!= 0) {
2486 lifr
.lifr_arp_muxid
= *orig_arpid
;
2487 (void) ioctl(*muxid_fd
, SIOCSLIFMUXID
, (caddr_t
)&lifr
);
2491 if (ioctl(*muxfd
, I_PUNLINK
, lifr
.lifr_ip_muxid
) < 0) {
2492 Perror2("I_PUNLINK", udp_dev_name
);
2493 /* Undo any changes we made */
2494 if (*orig_arpid
!= 0) {
2495 lifr
.lifr_arp_muxid
= *orig_arpid
;
2496 (void) ioctl(*muxid_fd
, SIOCSLIFMUXID
, (caddr_t
)&lifr
);
2504 * Helper function for mod*() functions. It I_PLINK's back the upper and
2505 * lower IP streams. Note that this function must be called after
2506 * ip_domux2fd(). In ip_domux2fd(), the global variable lifr is initialized
2507 * and ip_plink() needs information in lifr. So ip_domux2fd() and ip_plink()
2508 * must be called in pairs.
2511 * int muxfd: fd to /dev/udp{,6} for I_PLINK/I_PUNLINK
2512 * int muxid_fd: fd to /dev/udp{,6} for LIFMUXID
2513 * int ipfd_lowstr: fd to the lower IP stream.
2514 * int arpfd_lowstr: fd to the lower ARP stream.
2517 * -1 if operation fails, 0 otherwise.
2519 * Please see the big block comment above ifplumb() for the logic of the
2523 ip_plink(int muxfd
, int muxid_fd
, int ipfd_lowstr
, int arpfd_lowstr
,
2528 ip_muxid
= ioctl(muxfd
, I_PLINK
, ipfd_lowstr
);
2530 Perror2("I_PLINK", UDP_DEV_NAME
);
2535 * If there is an arp stream, plink it. If there is no
2536 * arp stream, then it is possible that the plumbing
2537 * utility could have stored any value in the arp_muxid.
2538 * If so, restore it from orig_arpid.
2540 if (arpfd_lowstr
!= -1) {
2541 if (ioctl(muxfd
, I_PLINK
, arpfd_lowstr
) < 0) {
2542 Perror2("I_PLINK", UDP_DEV_NAME
);
2545 } else if (orig_arpid
!= 0) {
2546 /* Undo the changes we did in ip_domux2fd */
2547 lifr
.lifr_arp_muxid
= orig_arpid
;
2548 lifr
.lifr_ip_muxid
= ip_muxid
;
2549 (void) ioctl(muxid_fd
, SIOCSLIFMUXID
, (caddr_t
)&lifr
);
2552 (void) close(muxfd
);
2553 (void) close(muxid_fd
);
2558 * The real function to perform module insertion/removal.
2561 * char *arg: the argument string module_name@position
2562 * char op: operation, either MODINSERT_OP or MODREMOVE_OP.
2565 * Before doing ip_domux2fd(), this function calls exit(1) in case of
2566 * error. After ip_domux2fd() is done, it returns -1 for error, 0
2570 modop(char *arg
, char op
)
2575 int ipfd_lowstr
; /* IP stream (lower stream of mux) to be plinked */
2576 int arpfd_lowstr
; /* ARP stream (lower stream of mux) to be plinked */
2577 struct strmodconf mod
;
2578 char *at_char
= "@";
2583 * We'd return -1, but foreachinterface() doesn't propagate the error
2584 * into the exit status, so we're forced to explicitly exit().
2586 if (!modcheck(name
))
2589 /* Need to save the original string for -a option. */
2590 if ((arg_str
= malloc(strlen(arg
) + 1)) == NULL
) {
2591 Perror0("cannot malloc");
2594 (void) strcpy(arg_str
, arg
);
2596 if (*arg_str
== *at_char
) {
2597 (void) fprintf(stderr
,
2598 "ifconfig: must supply a module name\n");
2601 mod
.mod_name
= strtok(arg_str
, at_char
);
2602 if (strlen(mod
.mod_name
) > FMNAMESZ
) {
2603 (void) fprintf(stderr
, "ifconfig: module name too long: %s\n",
2609 * Need to make sure that the core TCP/IP stack modules are not
2610 * removed. Otherwise, "bad" things can happen. If a module
2611 * is removed and inserted back, it loses its old state. But
2612 * the modules above it still have the old state. E.g. IP assumes
2613 * fast data path while tunnel after re-inserted assumes that it can
2614 * receive M_DATA only in fast data path for which it does not have
2615 * any state. This is a general caveat of _I_REMOVE/_I_INSERT.
2617 if (op
== MODREMOVE_OP
&&
2618 (strcmp(mod
.mod_name
, ARP_MOD_NAME
) == 0 ||
2619 strcmp(mod
.mod_name
, IP_MOD_NAME
) == 0)) {
2620 (void) fprintf(stderr
, "ifconfig: cannot remove %s\n",
2625 if ((pos_p
= strtok(NULL
, at_char
)) == NULL
) {
2626 (void) fprintf(stderr
, "ifconfig: must supply a position\n");
2629 mod
.pos
= atoi(pos_p
);
2631 if (ip_domux2fd(&muxfd
, &muxid_fd
, &ipfd_lowstr
, &arpfd_lowstr
,
2639 (void) printf("Inserting module %s at %d\n",
2640 mod
.mod_name
, mod
.pos
);
2642 if (ioctl(ipfd_lowstr
, _I_INSERT
, (caddr_t
)&mod
) < 0) {
2643 Perror2("fail to insert module", mod
.mod_name
);
2648 (void) printf("Removing module %s at %d\n",
2649 mod
.mod_name
, mod
.pos
);
2651 if (ioctl(ipfd_lowstr
, _I_REMOVE
, (caddr_t
)&mod
) < 0) {
2652 Perror2("fail to remove module", mod
.mod_name
);
2656 /* Should never get to here. */
2657 (void) fprintf(stderr
, "Unknown operation\n");
2661 return (ip_plink(muxfd
, muxid_fd
, ipfd_lowstr
, arpfd_lowstr
,
2666 modify_tun(iptun_params_t
*params
)
2668 dladm_status_t status
;
2670 if ((status
= ifconfig_dladm_open(name
, DATALINK_CLASS_IPTUN
,
2671 ¶ms
->iptun_param_linkid
)) == DLADM_STATUS_OK
)
2672 status
= dladm_iptun_modify(dlh
, params
, DLADM_OPT_ACTIVE
);
2673 if (status
!= DLADM_STATUS_OK
)
2674 dladmerr_exit(status
, name
);
2679 * Set tunnel source address
2683 setiftsrc(char *addr
, int64_t param
)
2685 iptun_params_t params
;
2687 params
.iptun_param_flags
= IPTUN_PARAM_LADDR
;
2688 (void) strlcpy(params
.iptun_param_laddr
, addr
,
2689 sizeof (params
.iptun_param_laddr
));
2690 return (modify_tun(¶ms
));
2694 * Set tunnel destination address
2698 setiftdst(char *addr
, int64_t param
)
2700 iptun_params_t params
;
2702 params
.iptun_param_flags
= IPTUN_PARAM_RADDR
;
2703 (void) strlcpy(params
.iptun_param_raddr
, addr
,
2704 sizeof (params
.iptun_param_raddr
));
2705 return (modify_tun(¶ms
));
2709 set_tun_prop(const char *propname
, char *value
)
2711 dladm_status_t status
;
2712 datalink_id_t linkid
;
2714 status
= ifconfig_dladm_open(name
, DATALINK_CLASS_IPTUN
, &linkid
);
2715 if (status
== DLADM_STATUS_OK
) {
2716 status
= dladm_set_linkprop(dlh
, linkid
, propname
, &value
, 1,
2719 if (status
!= DLADM_STATUS_OK
)
2720 dladmerr_exit(status
, name
);
2724 /* Set tunnel encapsulation limit. */
2727 set_tun_encap_limit(char *arg
, int64_t param
)
2729 return (set_tun_prop("encaplimit", arg
));
2732 /* Disable encapsulation limit. */
2735 clr_tun_encap_limit(char *arg
, int64_t param
)
2737 return (set_tun_encap_limit("-1", 0));
2740 /* Set tunnel hop limit. */
2743 set_tun_hop_limit(char *arg
, int64_t param
)
2745 return (set_tun_prop("hoplimit", arg
));
2750 setzone(char *arg
, int64_t param
)
2752 zoneid_t zoneid
= GLOBAL_ZONEID
;
2754 if (param
== NEXTARG
) {
2755 /* zone must be active */
2756 if ((zoneid
= getzoneidbyname(arg
)) == -1) {
2757 (void) fprintf(stderr
,
2758 "ifconfig: unknown zone '%s'\n", arg
);
2762 (void) strlcpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2763 lifr
.lifr_zoneid
= zoneid
;
2764 if (ioctl(s
, SIOCSLIFZONE
, (caddr_t
)&lifr
) == -1)
2765 Perror0_exit("SIOCSLIFZONE");
2769 /* Put interface into all zones */
2772 setallzones(char *arg
, int64_t param
)
2774 (void) strlcpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2775 lifr
.lifr_zoneid
= ALL_ZONES
;
2776 if (ioctl(s
, SIOCSLIFZONE
, (caddr_t
)&lifr
) == -1)
2777 Perror0_exit("SIOCSLIFZONE");
2781 /* Set source address to use */
2784 setifsrc(char *arg
, int64_t param
)
2789 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2792 * Argument can be either an interface name or "none". The latter means
2793 * that any previous selection is cleared.
2796 if (strchr(arg
, ':') != NULL
) {
2797 (void) fprintf(stderr
,
2798 "ifconfig: Cannot specify logical interface for usesrc \n");
2802 rval
= strcmp(arg
, NONE_STR
);
2804 if ((ifindex
= if_nametoindex(arg
)) == 0) {
2805 (void) strncpy(lifr
.lifr_name
, arg
, LIFNAMSIZ
);
2806 Perror0_exit("Could not get interface index");
2808 lifr
.lifr_index
= ifindex
;
2810 if (ioctl(s
, SIOCGLIFUSESRC
, (caddr_t
)&lifr
) != 0)
2811 Perror0_exit("Not a valid usesrc consumer");
2812 lifr
.lifr_index
= 0;
2816 (void) printf("setifsrc: lifr_name %s, lifr_index %d\n",
2817 lifr
.lifr_name
, lifr
.lifr_index
);
2819 if (ioctl(s
, SIOCSLIFUSESRC
, (caddr_t
)&lifr
) == -1) {
2821 Perror0_exit("Cannot reset usesrc group");
2823 Perror0_exit("Could not set source interface");
2830 * Print the interface status line associated with `ifname'
2833 ifstatus(const char *ifname
)
2836 char if_usesrc_name
[LIFNAMSIZ
];
2838 int n
, numifs
, rval
= 0;
2839 struct lifreq
*lifrp
;
2840 struct lifsrcof lifs
;
2842 (void) strncpy(lifr
.lifr_name
, ifname
, sizeof (lifr
.lifr_name
));
2843 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0) {
2844 Perror0_exit("status: SIOCGLIFFLAGS");
2846 flags
= lifr
.lifr_flags
;
2849 * In V4 compatibility mode, we don't print the IFF_IPV4 flag or
2850 * interfaces with IFF_IPV6 set.
2854 if (flags
& IFF_IPV6
)
2858 (void) printf("%s: ", ifname
);
2861 (void) strncpy(lifr
.lifr_name
, ifname
, sizeof (lifr
.lifr_name
));
2862 if (ioctl(s
, SIOCGLIFMETRIC
, (caddr_t
)&lifr
) < 0) {
2863 Perror0_exit("status: SIOCGLIFMETRIC");
2865 if (lifr
.lifr_metric
)
2866 (void) printf(" metric %d", lifr
.lifr_metric
);
2868 if (ioctl(s
, SIOCGLIFMTU
, (caddr_t
)&lifr
) >= 0)
2869 (void) printf(" mtu %u", lifr
.lifr_mtu
);
2871 /* don't print index or zone when in compatibility mode */
2873 if (ioctl(s
, SIOCGLIFINDEX
, (caddr_t
)&lifr
) >= 0)
2874 (void) printf(" index %d", lifr
.lifr_index
);
2876 * Stack instances use GLOBAL_ZONEID for IP data structures
2877 * even in the non-global zone.
2879 if (ioctl(s
, SIOCGLIFZONE
, (caddr_t
)&lifr
) >= 0 &&
2880 lifr
.lifr_zoneid
!= getzoneid() &&
2881 lifr
.lifr_zoneid
!= GLOBAL_ZONEID
) {
2882 char zone_name
[ZONENAME_MAX
];
2884 if (lifr
.lifr_zoneid
== ALL_ZONES
) {
2885 (void) printf("\n\tall-zones");
2886 } else if (getzonenamebyid(lifr
.lifr_zoneid
, zone_name
,
2887 sizeof (zone_name
)) < 0) {
2888 (void) printf("\n\tzone %d", lifr
.lifr_zoneid
);
2890 (void) printf("\n\tzone %s", zone_name
);
2895 if (ioctl(s
, SIOCGLIFINDEX
, (caddr_t
)&lifr
) >= 0) {
2896 lifs
.lifs_ifindex
= lifr
.lifr_index
;
2899 * Find the number of interfaces that use this interfaces'
2900 * address as a source address
2902 lifs
.lifs_buf
= NULL
;
2903 lifs
.lifs_maxlen
= 0;
2905 /* The first pass will give the bufsize we need */
2906 rval
= ioctl(s
, SIOCGLIFSRCOF
, (char *)&lifs
);
2908 if (lifs
.lifs_buf
!= NULL
) {
2909 free(lifs
.lifs_buf
);
2910 lifs
.lifs_buf
= NULL
;
2915 if (lifs
.lifs_len
<= lifs
.lifs_maxlen
)
2917 /* Use kernel's size + a small margin to avoid loops */
2918 lifs
.lifs_maxlen
= lifs
.lifs_len
+
2919 5 * sizeof (struct lifreq
);
2920 /* For the first pass, realloc acts like malloc */
2921 newbuf
= realloc(lifs
.lifs_buf
, lifs
.lifs_maxlen
);
2922 if (newbuf
== NULL
) {
2923 if (lifs
.lifs_buf
!= NULL
) {
2924 free(lifs
.lifs_buf
);
2925 lifs
.lifs_buf
= NULL
;
2930 lifs
.lifs_buf
= newbuf
;
2934 numifs
= lifs
.lifs_len
/ sizeof (struct lifreq
);
2936 lifrp
= lifs
.lifs_req
;
2937 (void) printf("\n\tsrcof");
2938 for (n
= numifs
; n
> 0; n
--, lifrp
++) {
2939 (void) printf(" %s", lifrp
->lifr_name
);
2943 if (lifs
.lifs_buf
!= NULL
)
2944 free(lifs
.lifs_buf
);
2947 /* Find the interface whose source address this interface uses */
2948 if (ioctl(s
, SIOCGLIFUSESRC
, (caddr_t
)&lifr
) == 0) {
2949 if (lifr
.lifr_index
!= 0) {
2950 if (if_indextoname(lifr
.lifr_index
,
2951 if_usesrc_name
) == NULL
) {
2952 (void) printf("\n\tusesrc ifIndex %d",
2955 (void) printf("\n\tusesrc %s", if_usesrc_name
);
2960 (void) putchar('\n');
2964 * Print the status of the interface. If an address family was
2965 * specified, show it and it only; otherwise, show them all.
2970 struct afswtch
*p
= afp
;
2972 datalink_id_t linkid
;
2974 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2975 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0) {
2976 Perror0_exit("status: SIOCGLIFFLAGS");
2979 flags
= lifr
.lifr_flags
;
2982 * Only print the interface status if the address family matches
2983 * the interface family flag.
2986 if (((p
->af_af
== AF_INET6
) && (flags
& IFF_IPV4
)) ||
2987 ((p
->af_af
== AF_INET
) && (flags
& IFF_IPV6
)))
2992 * In V4 compatibility mode, don't print IFF_IPV6 interfaces.
2994 if (v4compat
&& (flags
& IFF_IPV6
))
2999 if (ifconfig_dladm_open(name
, DATALINK_CLASS_IPTUN
, &linkid
) ==
3004 (*p
->af_status
)(1, flags
);
3006 for (p
= afs
; p
->af_name
; p
++) {
3007 /* set global af for use in p->af_status */
3009 (*p
->af_status
)(0, flags
);
3013 * Historically, 'ether' has been an address family,
3016 print_ifether(name
);
3021 * Print the status of the interface in a format that can be used to
3022 * reconfigure the interface later. Code stolen from status() above.
3026 configinfo(char *null
, int64_t param
)
3029 struct afswtch
*p
= afp
;
3031 char lifname
[LIFNAMSIZ
];
3032 char if_usesrc_name
[LIFNAMSIZ
];
3034 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3036 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0) {
3037 Perror0_exit("status: SIOCGLIFFLAGS");
3039 flags
= lifr
.lifr_flags
;
3042 (void) printf("configinfo: name %s flags 0x%llx af_af %d\n",
3043 name
, flags
, p
!= NULL
? p
->af_af
: -1);
3047 * Build the interface name to print (we cannot directly use `name'
3048 * because one cannot "plumb" ":0" interfaces).
3050 (void) strlcpy(lifname
, name
, LIFNAMSIZ
);
3051 if ((cp
= strchr(lifname
, ':')) != NULL
&& atoi(cp
+ 1) == 0)
3055 * if the interface is IPv4
3056 * if we have a IPv6 address family restriction return
3058 * if we are in IPv4 compatibility mode, clear out IFF_IPV4
3059 * so we don't print it.
3061 if (flags
& IFF_IPV4
) {
3062 if (p
&& p
->af_af
== AF_INET6
)
3067 (void) printf("%s inet plumb", lifname
);
3068 } else if (flags
& IFF_IPV6
) {
3070 * else if the interface is IPv6
3071 * if we have a IPv4 address family restriction return
3072 * or we are in IPv4 compatibiltiy mode, return.
3074 if (p
&& p
->af_af
== AF_INET
)
3079 (void) printf("%s inet6 plumb", lifname
);
3082 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3083 if (ioctl(s
, SIOCGLIFMETRIC
, (caddr_t
)&lifr
) < 0) {
3084 Perror0_exit("configinfo: SIOCGLIFMETRIC");
3086 if (lifr
.lifr_metric
)
3087 (void) printf(" metric %d ", lifr
.lifr_metric
);
3089 if (((flags
& (IFF_VIRTUAL
|IFF_LOOPBACK
)) != IFF_VIRTUAL
) &&
3090 ioctl(s
, SIOCGLIFMTU
, (caddr_t
)&lifr
) >= 0)
3091 (void) printf(" mtu %u", lifr
.lifr_mtu
);
3093 /* Index only applies to the zeroth interface */
3094 if (lifnum(name
) == 0) {
3095 if (ioctl(s
, SIOCGLIFINDEX
, (caddr_t
)&lifr
) >= 0)
3096 (void) printf(" index %d", lifr
.lifr_index
);
3099 if (ioctl(s
, SIOCGLIFUSESRC
, (caddr_t
)&lifr
) == 0) {
3100 if (lifr
.lifr_index
!= 0) {
3101 if (if_indextoname(lifr
.lifr_index
,
3102 if_usesrc_name
) != NULL
) {
3103 (void) printf(" usesrc %s", if_usesrc_name
);
3109 (*p
->af_configinfo
)(1, flags
);
3111 for (p
= afs
; p
->af_name
; p
++) {
3113 s
= socket(SOCKET_AF(p
->af_af
), SOCK_DGRAM
, 0);
3114 /* set global af for use in p->af_configinfo */
3117 Perror0_exit("socket");
3119 (*p
->af_configinfo
)(0, flags
);
3123 (void) putchar('\n');
3128 print_tsec(iptun_params_t
*params
)
3132 (void) printf("\ttunnel security settings ");
3133 if (!(params
->iptun_param_flags
& IPTUN_PARAM_SECINFO
)) {
3134 (void) printf("--> use 'ipsecconf -ln -i %s'", name
);
3136 ipsr
= ¶ms
->iptun_param_secinfo
;
3137 if (ipsr
->ipsr_ah_req
& IPSEC_PREF_REQUIRED
) {
3138 (void) printf("ah (%s) ",
3139 rparsealg(ipsr
->ipsr_auth_alg
, IPSEC_PROTO_AH
));
3141 if (ipsr
->ipsr_esp_req
& IPSEC_PREF_REQUIRED
) {
3142 (void) printf("esp (%s",
3143 rparsealg(ipsr
->ipsr_esp_alg
, IPSEC_PROTO_ESP
));
3144 (void) printf("/%s)",
3145 rparsealg(ipsr
->ipsr_esp_auth_alg
, IPSEC_PROTO_AH
));
3148 (void) printf("\n");
3152 tun_status(datalink_id_t linkid
)
3154 iptun_params_t params
;
3155 char propval
[DLADM_PROP_VAL_MAX
];
3158 boolean_t tabbed
= _B_FALSE
;
3160 params
.iptun_param_linkid
= linkid
;
3162 /* If dladm_iptun_getparams() fails, assume we are not a tunnel. */
3164 if (dladm_iptun_getparams(dlh
, ¶ms
, DLADM_OPT_ACTIVE
) !=
3168 switch (params
.iptun_param_type
) {
3169 case IPTUN_TYPE_IPV4
:
3170 case IPTUN_TYPE_6TO4
:
3171 (void) printf("\tinet");
3173 case IPTUN_TYPE_IPV6
:
3174 (void) printf("\tinet6");
3177 dladmerr_exit(DLADM_STATUS_IPTUNTYPE
, name
);
3182 * There is always a source address. If it hasn't been explicitly
3183 * set, the API will pass back a buffer containing the unspecified
3186 (void) printf(" tunnel src %s ", params
.iptun_param_laddr
);
3188 if (params
.iptun_param_flags
& IPTUN_PARAM_RADDR
)
3189 (void) printf("tunnel dst %s\n", params
.iptun_param_raddr
);
3191 (void) putchar('\n');
3193 if (params
.iptun_param_flags
& IPTUN_PARAM_IPSECPOL
)
3194 print_tsec(¶ms
);
3196 valptr
[0] = propval
;
3197 if (dladm_get_linkprop(dlh
, linkid
, DLADM_PROP_VAL_CURRENT
, "hoplimit",
3198 (char **)valptr
, &valcnt
) == DLADM_STATUS_OK
) {
3199 (void) printf("\ttunnel hop limit %s ", propval
);
3203 if (dladm_get_linkprop(dlh
, linkid
, DLADM_PROP_VAL_CURRENT
,
3204 "encaplimit", (char **)valptr
, &valcnt
) == DLADM_STATUS_OK
) {
3208 (void) putchar('\t');
3211 elim
= strtol(propval
, NULL
, 10);
3213 (void) printf("tunnel encapsulation limit %s", propval
);
3215 (void) printf("tunnel encapsulation limit disabled");
3219 (void) putchar('\n');
3223 in_status(int force
, uint64_t flags
)
3225 struct sockaddr_in
*sin
, *laddr
;
3226 struct sockaddr_in netmask
= { AF_INET
};
3229 (void) printf("in_status(%s) flags 0x%llx\n", name
, flags
);
3231 /* only print status for IPv4 interfaces */
3232 if (!(flags
& IFF_IPV4
))
3235 if (!(flags
& IFF_NOLOCAL
)) {
3236 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3237 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
3238 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3242 (void) memset(&lifr
.lifr_addr
, 0,
3243 sizeof (lifr
.lifr_addr
));
3245 Perror0_exit("in_status: SIOCGLIFADDR");
3247 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3248 (void) printf("\tinet %s ", inet_ntoa(sin
->sin_addr
));
3251 (void) printf("\tinet ");
3254 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3255 if (ioctl(s
, SIOCGLIFSUBNET
, (caddr_t
)&lifr
) < 0) {
3256 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3260 (void) memset(&lifr
.lifr_addr
, 0,
3261 sizeof (lifr
.lifr_addr
));
3263 Perror0_exit("in_status: SIOCGLIFSUBNET");
3266 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3267 if ((flags
& IFF_NOLOCAL
) ||
3268 sin
->sin_addr
.s_addr
!= laddr
->sin_addr
.s_addr
) {
3269 (void) printf("subnet %s/%d ", inet_ntoa(sin
->sin_addr
),
3272 if (sin
->sin_family
!= AF_INET
) {
3273 (void) printf("Wrong family: %d\n", sin
->sin_family
);
3276 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3277 if (ioctl(s
, SIOCGLIFNETMASK
, (caddr_t
)&lifr
) < 0) {
3278 if (errno
!= EADDRNOTAVAIL
)
3279 Perror0_exit("in_status: SIOCGLIFNETMASK");
3280 (void) memset(&lifr
.lifr_addr
, 0, sizeof (lifr
.lifr_addr
));
3283 ((struct sockaddr_in
*)&lifr
.lifr_addr
)->sin_addr
;
3284 if (flags
& IFF_POINTOPOINT
) {
3285 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3286 if (ioctl(s
, SIOCGLIFDSTADDR
, (caddr_t
)&lifr
) < 0) {
3287 if (errno
== EADDRNOTAVAIL
)
3288 (void) memset(&lifr
.lifr_addr
, 0,
3289 sizeof (lifr
.lifr_addr
));
3291 Perror0_exit("in_status: SIOCGLIFDSTADDR");
3293 sin
= (struct sockaddr_in
*)&lifr
.lifr_dstaddr
;
3294 (void) printf("--> %s ", inet_ntoa(sin
->sin_addr
));
3296 (void) printf("netmask %x ", ntohl(netmask
.sin_addr
.s_addr
));
3297 if (flags
& IFF_BROADCAST
) {
3298 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3299 if (ioctl(s
, SIOCGLIFBRDADDR
, (caddr_t
)&lifr
) < 0) {
3300 if (errno
== EADDRNOTAVAIL
)
3301 (void) memset(&lifr
.lifr_addr
, 0,
3302 sizeof (lifr
.lifr_addr
));
3304 Perror0_exit("in_status: SIOCGLIFBRDADDR");
3306 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3307 if (sin
->sin_addr
.s_addr
!= 0) {
3308 (void) printf("broadcast %s",
3309 inet_ntoa(sin
->sin_addr
));
3312 /* If there is a groupname, print it for only the physical interface */
3313 if (strchr(name
, ':') == NULL
) {
3314 if (ioctl(s
, SIOCGLIFGROUPNAME
, &lifr
) >= 0 &&
3315 lifr
.lifr_groupname
[0] != '\0') {
3316 (void) printf("\n\tgroupname %s", lifr
.lifr_groupname
);
3319 (void) putchar('\n');
3323 in6_status(int force
, uint64_t flags
)
3325 char abuf
[INET6_ADDRSTRLEN
];
3326 struct sockaddr_in6
*sin6
, *laddr6
;
3329 (void) printf("in6_status(%s) flags 0x%llx\n", name
, flags
);
3331 if (!(flags
& IFF_IPV6
))
3334 if (!(flags
& IFF_NOLOCAL
)) {
3335 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3336 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
3337 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3341 (void) memset(&lifr
.lifr_addr
, 0,
3342 sizeof (lifr
.lifr_addr
));
3344 Perror0_exit("in_status6: SIOCGLIFADDR");
3346 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3347 (void) printf("\tinet6 %s/%d ",
3348 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3349 abuf
, sizeof (abuf
)),
3353 (void) printf("\tinet6 ");
3355 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3356 if (ioctl(s
, SIOCGLIFSUBNET
, (caddr_t
)&lifr
) < 0) {
3357 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3361 (void) memset(&lifr
.lifr_addr
, 0,
3362 sizeof (lifr
.lifr_addr
));
3364 Perror0_exit("in_status6: SIOCGLIFSUBNET");
3366 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3367 if ((flags
& IFF_NOLOCAL
) ||
3368 !IN6_ARE_ADDR_EQUAL(&sin6
->sin6_addr
, &laddr6
->sin6_addr
)) {
3369 (void) printf("subnet %s/%d ",
3370 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3371 abuf
, sizeof (abuf
)),
3374 if (sin6
->sin6_family
!= AF_INET6
) {
3375 (void) printf("Wrong family: %d\n", sin6
->sin6_family
);
3377 if (flags
& IFF_POINTOPOINT
) {
3378 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3379 if (ioctl(s
, SIOCGLIFDSTADDR
, (caddr_t
)&lifr
) < 0) {
3380 if (errno
== EADDRNOTAVAIL
)
3381 (void) memset(&lifr
.lifr_addr
, 0,
3382 sizeof (lifr
.lifr_addr
));
3384 Perror0_exit("in_status6: SIOCGLIFDSTADDR");
3386 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_dstaddr
;
3387 (void) printf("--> %s ",
3388 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3389 abuf
, sizeof (abuf
)));
3392 (void) putchar('\n');
3393 (void) putchar('\t');
3394 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3395 if (ioctl(s
, SIOCGLIFTOKEN
, (caddr_t
)&lifr
) < 0) {
3396 if (errno
== EADDRNOTAVAIL
|| errno
== EINVAL
)
3397 (void) memset(&lifr
.lifr_addr
, 0,
3398 sizeof (lifr
.lifr_addr
));
3400 Perror0_exit("in_status6: SIOCGLIFTOKEN");
3402 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3403 (void) printf("token %s/%d ",
3404 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3405 abuf
, sizeof (abuf
)),
3408 if (ioctl(s
, SIOCGLIFLNKINFO
, (caddr_t
)&lifr
) < 0) {
3409 if (errno
!= EINVAL
) {
3410 Perror0_exit("in_status6: SIOCGLIFLNKINFO");
3413 (void) printf("maxhops %u, reachtime %u ms, "
3414 "reachretrans %u ms, maxmtu %u ",
3415 lifr
.lifr_ifinfo
.lir_maxhops
,
3416 lifr
.lifr_ifinfo
.lir_reachtime
,
3417 lifr
.lifr_ifinfo
.lir_reachretrans
,
3418 lifr
.lifr_ifinfo
.lir_maxmtu
);
3421 /* If there is a groupname, print it for only the physical interface */
3422 if (strchr(name
, ':') == NULL
) {
3423 if (ioctl(s
, SIOCGLIFGROUPNAME
, &lifr
) >= 0 &&
3424 lifr
.lifr_groupname
[0] != '\0') {
3425 (void) printf("\n\tgroupname %s", lifr
.lifr_groupname
);
3428 (void) putchar('\n');
3432 in_configinfo(int force
, uint64_t flags
)
3434 struct sockaddr_in
*sin
, *laddr
;
3435 struct sockaddr_in netmask
= { AF_INET
};
3438 (void) printf("in_configinfo(%s) flags 0x%llx\n", name
, flags
);
3440 /* only configinfo info for IPv4 interfaces */
3441 if (!(flags
& IFF_IPV4
))
3444 if (!(flags
& IFF_NOLOCAL
)) {
3445 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3446 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
3447 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3451 (void) memset(&lifr
.lifr_addr
, 0,
3452 sizeof (lifr
.lifr_addr
));
3454 Perror0_exit("in_configinfo: SIOCGLIFADDR");
3456 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3457 (void) printf(" set %s ", inet_ntoa(sin
->sin_addr
));
3461 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3462 if (ioctl(s
, SIOCGLIFSUBNET
, (caddr_t
)&lifr
) < 0) {
3463 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3467 (void) memset(&lifr
.lifr_addr
, 0,
3468 sizeof (lifr
.lifr_addr
));
3470 Perror0_exit("in_configinfo: SIOCGLIFSUBNET");
3473 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3475 if ((flags
& IFF_NOLOCAL
) ||
3476 sin
->sin_addr
.s_addr
!= laddr
->sin_addr
.s_addr
) {
3477 (void) printf(" subnet %s/%d ", inet_ntoa(sin
->sin_addr
),
3480 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3481 if (ioctl(s
, SIOCGLIFNETMASK
, (caddr_t
)&lifr
) < 0) {
3482 if (errno
!= EADDRNOTAVAIL
)
3483 Perror0_exit("in_configinfo: SIOCGLIFNETMASK");
3484 (void) memset(&lifr
.lifr_addr
, 0, sizeof (lifr
.lifr_addr
));
3487 ((struct sockaddr_in
*)&lifr
.lifr_addr
)->sin_addr
;
3488 if (flags
& IFF_POINTOPOINT
) {
3489 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3490 if (ioctl(s
, SIOCGLIFDSTADDR
, (caddr_t
)&lifr
) < 0) {
3491 if (errno
== EADDRNOTAVAIL
)
3492 (void) memset(&lifr
.lifr_addr
, 0,
3493 sizeof (lifr
.lifr_addr
));
3495 Perror0_exit("in_configinfo: SIOCGLIFDSTADDR");
3497 sin
= (struct sockaddr_in
*)&lifr
.lifr_dstaddr
;
3498 (void) printf(" destination %s ", inet_ntoa(sin
->sin_addr
));
3500 (void) printf(" netmask 0x%x ", ntohl(netmask
.sin_addr
.s_addr
));
3501 if (flags
& IFF_BROADCAST
) {
3502 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3503 if (ioctl(s
, SIOCGLIFBRDADDR
, (caddr_t
)&lifr
) < 0) {
3504 if (errno
== EADDRNOTAVAIL
)
3505 (void) memset(&lifr
.lifr_addr
, 0,
3506 sizeof (lifr
.lifr_addr
));
3508 Perror0_exit("in_configinfo: SIOCGLIFBRDADDR");
3510 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3511 if (sin
->sin_addr
.s_addr
!= 0) {
3512 (void) printf(" broadcast %s ",
3513 inet_ntoa(sin
->sin_addr
));
3517 /* If there is a groupname, print it for only the zeroth interface */
3518 if (lifnum(name
) == 0) {
3519 if (ioctl(s
, SIOCGLIFGROUPNAME
, &lifr
) >= 0 &&
3520 lifr
.lifr_groupname
[0] != '\0') {
3521 (void) printf(" group %s ", lifr
.lifr_groupname
);
3525 /* Print flags to configure */
3526 print_config_flags(AF_INET
, flags
);
3530 in6_configinfo(int force
, uint64_t flags
)
3532 char abuf
[INET6_ADDRSTRLEN
];
3533 struct sockaddr_in6
*sin6
, *laddr6
;
3536 (void) printf("in6_configinfo(%s) flags 0x%llx\n", name
,
3539 if (!(flags
& IFF_IPV6
))
3542 if (!(flags
& IFF_NOLOCAL
)) {
3543 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3544 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
3545 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3549 (void) memset(&lifr
.lifr_addr
, 0,
3550 sizeof (lifr
.lifr_addr
));
3552 Perror0_exit("in6_configinfo: SIOCGLIFADDR");
3554 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3555 (void) printf(" set %s/%d ",
3556 inet_ntop(AF_INET6
, &sin6
->sin6_addr
, abuf
, sizeof (abuf
)),
3560 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3561 if (ioctl(s
, SIOCGLIFSUBNET
, (caddr_t
)&lifr
) < 0) {
3562 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3566 (void) memset(&lifr
.lifr_addr
, 0,
3567 sizeof (lifr
.lifr_addr
));
3569 Perror0_exit("in6_configinfo: SIOCGLIFSUBNET");
3571 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3572 if ((flags
& IFF_NOLOCAL
) ||
3573 !IN6_ARE_ADDR_EQUAL(&sin6
->sin6_addr
, &laddr6
->sin6_addr
)) {
3574 (void) printf(" subnet %s/%d ",
3575 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3576 abuf
, sizeof (abuf
)),
3580 if (flags
& IFF_POINTOPOINT
) {
3581 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3582 if (ioctl(s
, SIOCGLIFDSTADDR
, (caddr_t
)&lifr
) < 0) {
3583 if (errno
== EADDRNOTAVAIL
)
3584 (void) memset(&lifr
.lifr_addr
, 0,
3585 sizeof (lifr
.lifr_addr
));
3587 Perror0_exit("in6_configinfo: SIOCGLIFDSTADDR");
3589 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_dstaddr
;
3590 (void) printf(" destination %s ",
3591 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3592 abuf
, sizeof (abuf
)));
3595 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3596 if (ioctl(s
, SIOCGLIFTOKEN
, (caddr_t
)&lifr
) < 0) {
3597 if (errno
== EADDRNOTAVAIL
|| errno
== EINVAL
)
3598 (void) memset(&lifr
.lifr_addr
, 0,
3599 sizeof (lifr
.lifr_addr
));
3601 Perror0_exit("in6_configinfo: SIOCGLIFTOKEN");
3603 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3604 (void) printf(" token %s/%d ",
3605 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3606 abuf
, sizeof (abuf
)),
3610 /* If there is a groupname, print it for only the zeroth interface */
3611 if (lifnum(name
) == 0) {
3612 if (ioctl(s
, SIOCGLIFGROUPNAME
, &lifr
) >= 0 &&
3613 lifr
.lifr_groupname
[0] != '\0') {
3614 (void) printf(" group %s ", lifr
.lifr_groupname
);
3618 /* Print flags to configure */
3619 print_config_flags(AF_INET6
, flags
);
3623 * If this is a physical interface then remove it.
3624 * If it is a logical interface name use SIOCLIFREMOVEIF to
3625 * remove it. In both cases fail if it doesn't exist.
3629 inetunplumb(char *arg
, int64_t param
)
3631 ipadm_status_t istatus
;
3633 istatus
= ipadm_delete_if(iph
, name
, afp
->af_af
, IPADM_OPT_ACTIVE
);
3634 if (istatus
!= IPADM_SUCCESS
) {
3635 (void) fprintf(stderr
, "ifconfig: cannot unplumb %s: %s\n",
3636 name
, ipadm_status2str(istatus
));
3644 * Create the interface in `name', using ipadm_create_if(). If `name' is a
3645 * logical interface or loopback interface, ipadm_create_if() uses
3646 * SIOCLIFADDIF to create it.
3650 inetplumb(char *arg
, int64_t param
)
3652 ipadm_status_t istatus
;
3654 istatus
= ipadm_create_if(iph
, name
, afp
->af_af
, IPADM_OPT_ACTIVE
);
3655 if (istatus
!= IPADM_SUCCESS
) {
3656 (void) fprintf(stderr
, "ifconfig: cannot plumb %s: %s\n",
3657 name
, ipadm_status2str(istatus
));
3658 if (istatus
!= IPADM_IF_EXISTS
)
3666 inetipmp(char *arg
, int64_t param
)
3671 * Treat e.g. "ifconfig ipmp0:2 ipmp" as "ifconfig ipmp0:2 plumb".
3672 * Otherwise, try to create the requested IPMP interface.
3674 if (strchr(name
, ':') != NULL
)
3675 retval
= inetplumb(arg
, param
);
3677 retval
= create_ipmp(name
, afp
->af_af
, name
, _B_FALSE
);
3680 * We'd return -1, but foreachinterface() doesn't propagate the error
3681 * into the exit status, so we're forced to explicitly exit().
3689 * Create an IPMP group `grname' with address family `af'. If `ifname' is
3690 * non-NULL, it specifies the interface name to use. Otherwise, use the name
3691 * ipmpN, where N corresponds to the lowest available integer. If `implicit'
3692 * is set, then the group is being created as a side-effect of placing an
3693 * underlying interface in a group. Also start in.mpathd if necessary.
3696 create_ipmp(const char *grname
, int af
, const char *ifname
, boolean_t implicit
)
3698 static int ipmp_daemon_started
;
3699 uint32_t flags
= IPADM_OPT_IPMP
|IPADM_OPT_ACTIVE
;
3700 ipadm_status_t istatus
;
3703 (void) printf("create_ipmp: ifname %s grname %s af %d\n",
3704 ifname
!= NULL
? ifname
: "NULL", grname
, af
);
3708 * ipadm_create_if() creates the IPMP interface and fills in the
3709 * ppa in lifr.lifr_name, if `ifname'="ipmp".
3711 (void) strlcpy(lifr
.lifr_name
, (ifname
? ifname
: "ipmp"),
3712 sizeof (lifr
.lifr_name
));
3714 flags
|= IPADM_OPT_GENPPA
;
3715 istatus
= ipadm_create_if(iph
, lifr
.lifr_name
, af
, flags
);
3716 if (istatus
!= IPADM_SUCCESS
) {
3717 (void) fprintf(stderr
, "ifconfig: cannot create IPMP interface "
3718 "%s: %s\n", grname
, ipadm_status2str(istatus
));
3723 * To preserve backward-compatibility, always bring up the link-local
3724 * address for implicitly-created IPv6 IPMP interfaces.
3726 if (implicit
&& af
== AF_INET6
) {
3727 if (ioctl(s6
, SIOCGLIFFLAGS
, &lifr
) == 0) {
3728 lifr
.lifr_flags
|= IFF_UP
;
3729 (void) ioctl(s6
, SIOCSLIFFLAGS
, &lifr
);
3734 * If the caller requested a different group name, issue a
3735 * SIOCSLIFGROUPNAME on the new IPMP interface.
3737 if (strcmp(lifr
.lifr_name
, grname
) != 0) {
3738 (void) strlcpy(lifr
.lifr_groupname
, grname
, LIFGRNAMSIZ
);
3739 if (ioctl(s
, SIOCSLIFGROUPNAME
, &lifr
) == -1) {
3740 Perror0("SIOCSLIFGROUPNAME");
3746 * If we haven't done so yet, ensure in.mpathd is started.
3748 if (ipmp_daemon_started
++ == 0)
3749 start_ipmp_daemon();
3755 * Start in.mpathd if it's not already running.
3758 start_ipmp_daemon(void)
3761 ipmp_handle_t ipmp_handle
;
3764 * Ping in.mpathd to see if it's running already.
3766 if ((retval
= ipmp_open(&ipmp_handle
)) != IPMP_SUCCESS
) {
3767 (void) fprintf(stderr
, "ifconfig: cannot create IPMP handle: "
3768 "%s\n", ipmp_errmsg(retval
));
3772 retval
= ipmp_ping_daemon(ipmp_handle
);
3773 ipmp_close(ipmp_handle
);
3776 case IPMP_ENOMPATHD
:
3781 (void) fprintf(stderr
, "ifconfig: cannot ping in.mpathd: %s\n",
3782 ipmp_errmsg(retval
));
3787 * Start in.mpathd. Note that in.mpathd will handle multiple
3788 * incarnations (ipmp_ping_daemon() is just an optimization) so we
3789 * don't need to worry about racing with another ifconfig process.
3793 Perror0_exit("start_ipmp_daemon: fork");
3796 (void) execl(MPATHD_PATH
, MPATHD_PATH
, NULL
);
3805 * Bring the address named by `ifaddrp' up or down. Doesn't trust any mutable
3806 * values in ia_flags since they may be stale.
3809 ifaddr_op(ifaddrlistx_t
*ifaddrp
, boolean_t up
)
3811 struct lifreq lifrl
; /* Local lifreq struct */
3812 int fd
= (ifaddrp
->ia_flags
& IFF_IPV4
) ? s4
: s6
;
3814 (void) memset(&lifrl
, 0, sizeof (lifrl
));
3815 (void) strlcpy(lifrl
.lifr_name
, ifaddrp
->ia_name
, LIFNAMSIZ
);
3816 if (ioctl(fd
, SIOCGLIFFLAGS
, &lifrl
) == -1)
3820 lifrl
.lifr_flags
|= IFF_UP
;
3822 lifrl
.lifr_flags
&= ~IFF_UP
;
3824 if (ioctl(fd
, SIOCSLIFFLAGS
, &lifrl
) == -1)
3828 * If we're trying to bring the address down, ensure that DAD activity
3829 * (observable by IFF_DUPLICATE) has also been stopped.
3831 if (!up
&& ioctl(fd
, SIOCGLIFFLAGS
, &lifrl
) != -1 &&
3832 lifrl
.lifr_flags
& IFF_DUPLICATE
) {
3833 if (ioctl(fd
, SIOCGLIFADDR
, &lifrl
) == -1 ||
3834 ioctl(fd
, SIOCSLIFADDR
, &lifrl
) == -1) {
3842 ifaddr_up(ifaddrlistx_t
*ifaddrp
)
3844 return (ifaddr_op(ifaddrp
, _B_TRUE
));
3848 ifaddr_down(ifaddrlistx_t
*ifaddrp
)
3850 return (ifaddr_op(ifaddrp
, _B_FALSE
));
3854 * Open the global libdladm handle "dlh" if it isn't already opened. The
3855 * caller may optionally supply a link name to obtain its linkid. If a link
3856 * of a specific class or classes is required, reqclass specifies the class
3859 static dladm_status_t
3860 ifconfig_dladm_open(const char *name
, datalink_class_t reqclass
,
3861 datalink_id_t
*linkid
)
3863 dladm_status_t status
= DLADM_STATUS_OK
;
3864 datalink_class_t
class;
3867 if ((status
= dladm_open(&dlh
)) != DLADM_STATUS_OK
)
3869 dlh_opened
= _B_TRUE
;
3872 status
= dladm_name2info(dlh
, name
, linkid
, NULL
, &class, NULL
);
3873 if (status
== DLADM_STATUS_OK
) {
3874 if (!(class & reqclass
))
3875 status
= DLADM_STATUS_LINKINVAL
;
3882 * This function checks if we can use libipadm API's. We will only
3883 * call libipadm functions for non-IPMP interfaces. This check is
3884 * temporary until libipadm supports IPMP interfaces.
3887 ifconfig_use_libipadm(int s
, const char *lifname
)
3889 struct lifreq lifr1
;
3891 (void) strlcpy(lifr1
.lifr_name
, lifname
, sizeof (lifr1
.lifr_name
));
3892 if (ioctl(s
, SIOCGLIFGROUPNAME
, (caddr_t
)&lifr1
) < 0) {
3893 (void) strncpy(lifr
.lifr_name
, lifname
,
3894 sizeof (lifr
.lifr_name
));
3895 Perror0_exit("error");
3898 return (lifr1
.lifr_groupname
[0] == '\0');
3902 ipadmerr_exit(ipadm_status_t status
, const char *str
)
3904 (void) fprintf(stderr
, "ifconfig: %s: %s\n", str
,
3905 ipadm_status2str(status
));
3910 dladmerr_exit(dladm_status_t status
, const char *str
)
3912 char errstr
[DLADM_STRSIZE
];
3914 (void) fprintf(stderr
, "%s: %s\n", str
,
3915 dladm_status2str(status
, errstr
));
3920 Perror0(const char *cmd
)
3922 Perror2(cmd
, lifr
.lifr_name
);
3926 Perror0_exit(const char *cmd
)
3933 Perror2(const char *cmd
, const char *str
)
3937 (void) fprintf(stderr
, "ifconfig: %s: ", cmd
);
3941 (void) fprintf(stderr
, "%s: no such interface\n", str
);
3944 (void) fprintf(stderr
, "%s: permission denied\n", str
);
3947 (void) fprintf(stderr
, "%s: already exists\n", str
);
3950 (void) fprintf(stderr
, "%s: interface name too long\n", str
);
3953 (void) fprintf(stderr
, "%s: logical interface id is outside "
3954 "allowed range\n", str
);
3963 * Print out error message (Perror2()) and exit
3966 Perror2_exit(const char *cmd
, const char *str
)
3974 Perrdlpi(const char *cmd
, const char *linkname
, int err
)
3976 (void) fprintf(stderr
, "ifconfig: %s \"%s\": %s\n", cmd
,
3977 linkname
, dlpi_strerror(err
));
3981 * Print out error message (Perrdlpi()) and exit
3984 Perrdlpi_exit(const char *cmd
, const char *linkname
, int err
)
3986 Perrdlpi(cmd
, linkname
, err
);
3991 * If the last argument is non-NULL allow a <addr>/<n> syntax and
3992 * pass out <n> in *plenp.
3993 * If <n> doesn't parse return BAD_ADDR as *plenp.
3994 * If no /<n> is present return NO_PREFIX as *plenp.
3997 in_getaddr(char *s
, struct sockaddr
*saddr
, int *plenp
)
3999 /* LINTED: alignment */
4000 struct sockaddr_in
*sin
= (struct sockaddr_in
*)saddr
;
4006 (void) strncpy(str
, s
, sizeof (str
));
4009 * Look for '/'<n> is plenp
4011 if (plenp
!= NULL
) {
4014 *plenp
= in_getprefixlen(str
, _B_TRUE
, IP_ABITS
);
4015 if (*plenp
== BAD_ADDR
)
4017 cp
= strchr(str
, '/');
4020 } else if (strchr(str
, '/') != NULL
) {
4021 (void) fprintf(stderr
, "ifconfig: %s: unexpected '/'\n", str
);
4025 (void) memset(sin
, 0, sizeof (*sin
));
4028 * Try to catch attempts to set the broadcast address to all 1's.
4030 if (strcmp(str
, "255.255.255.255") == 0 ||
4031 (strtoul(str
, (char **)NULL
, 0) == 0xffffffffUL
)) {
4032 sin
->sin_family
= AF_INET
;
4033 sin
->sin_addr
.s_addr
= 0xffffffff;
4037 hp
= getipnodebyname(str
, AF_INET
, 0, &error_num
);
4039 sin
->sin_family
= hp
->h_addrtype
;
4040 (void) memcpy(&sin
->sin_addr
, hp
->h_addr
, hp
->h_length
);
4044 np
= getnetbyname(str
);
4046 sin
->sin_family
= np
->n_addrtype
;
4047 sin
->sin_addr
= inet_makeaddr(np
->n_net
, INADDR_ANY
);
4050 if (error_num
== TRY_AGAIN
) {
4051 (void) fprintf(stderr
, "ifconfig: %s: bad address "
4052 "(try again later)\n", s
);
4054 (void) fprintf(stderr
, "ifconfig: %s: bad address\n", s
);
4060 * If the last argument is non-NULL allow a <addr>/<n> syntax and
4061 * pass out <n> in *plenp.
4062 * If <n> doesn't parse return BAD_ADDR as *plenp.
4063 * If no /<n> is present return NO_PREFIX as *plenp.
4066 in6_getaddr(char *s
, struct sockaddr
*saddr
, int *plenp
)
4068 /* LINTED: alignment */
4069 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)saddr
;
4074 (void) strncpy(str
, s
, sizeof (str
));
4077 * Look for '/'<n> is plenp
4079 if (plenp
!= NULL
) {
4082 *plenp
= in_getprefixlen(str
, _B_TRUE
, IPV6_ABITS
);
4083 if (*plenp
== BAD_ADDR
)
4085 cp
= strchr(str
, '/');
4088 } else if (strchr(str
, '/') != NULL
) {
4089 (void) fprintf(stderr
, "ifconfig: %s: unexpected '/'\n", str
);
4093 (void) memset(sin6
, 0, sizeof (*sin6
));
4095 hp
= getipnodebyname(str
, AF_INET6
, 0, &error_num
);
4097 sin6
->sin6_family
= hp
->h_addrtype
;
4098 (void) memcpy(&sin6
->sin6_addr
, hp
->h_addr
, hp
->h_length
);
4102 if (error_num
== TRY_AGAIN
) {
4103 (void) fprintf(stderr
, "ifconfig: %s: bad address "
4104 "(try again later)\n", s
);
4106 (void) fprintf(stderr
, "ifconfig: %s: bad address\n", s
);
4112 * If "slash" is zero this parses the whole string as
4113 * an integer. With "slash" non zero it parses the tail part as an integer.
4115 * If it is not a valid integer this returns BAD_ADDR.
4116 * If there is /<n> present this returns NO_PREFIX.
4119 in_getprefixlen(char *addr
, boolean_t slash
, int max_plen
)
4125 str
= strchr(addr
, '/');
4132 prefixlen
= strtol(str
, &end
, 10);
4137 if (max_plen
!= 0 && max_plen
< prefixlen
)
4143 * Convert a prefix length to a mask.
4144 * Returns 1 if ok. 0 otherwise.
4145 * Assumes the mask array is zero'ed by the caller.
4148 in_prefixlentomask(int prefixlen
, int maxlen
, uchar_t
*mask
)
4150 if (prefixlen
< 0 || prefixlen
> maxlen
)
4153 while (prefixlen
> 0) {
4154 if (prefixlen
>= 8) {
4159 *mask
|= 1 << (8 - prefixlen
);
4166 print_flags(uint64_t flags
)
4168 boolean_t first
= _B_TRUE
;
4171 (void) printf("flags=%llx", flags
);
4172 cnt
= sizeof (if_flags_tbl
) / sizeof (if_flags_t
);
4173 for (i
= 0; i
< cnt
; i
++) {
4174 if (flags
& if_flags_tbl
[i
].iff_value
) {
4180 * It has to be here and not with the
4181 * printf below because for the last one,
4182 * we don't want a comma before the ">".
4186 (void) printf("%s", if_flags_tbl
[i
].iff_name
);
4194 print_config_flags(int af
, uint64_t flags
)
4196 if_config_cmd_t
*cmdp
;
4198 for (cmdp
= if_config_cmd_tbl
; cmdp
->iff_flag
!= 0; cmdp
++) {
4199 if ((flags
& cmdp
->iff_flag
) &&
4200 (cmdp
->iff_af
== AF_UNSPEC
|| cmdp
->iff_af
== af
)) {
4201 (void) printf("%s ", cmdp
->iff_name
);
4207 * Use the configured directory lookup mechanism (e.g. files/NIS/...)
4208 * to find the network mask. Returns true if we found one to set.
4210 * The parameter addr_set controls whether we should get the address of
4211 * the working interface for the netmask query. If addr_set is true,
4212 * we will use the address provided. Otherwise, we will find the working
4213 * interface's address and use it instead.
4216 in_getmask(struct sockaddr_in
*saddr
, boolean_t addr_set
)
4218 struct sockaddr_in ifaddr
;
4221 * Read the address from the interface if it is not passed in.
4224 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
4225 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
4226 if (errno
!= EADDRNOTAVAIL
) {
4227 (void) fprintf(stderr
, "Need net number for "
4232 ifaddr
= *((struct sockaddr_in
*)&lifr
.lifr_addr
);
4234 ifaddr
.sin_addr
= saddr
->sin_addr
;
4236 if (getnetmaskbyaddr(ifaddr
.sin_addr
, &saddr
->sin_addr
) == 0) {
4237 saddr
->sin_family
= AF_INET
;
4244 lifnum(const char *ifname
)
4248 if ((cp
= strchr(ifname
, ':')) == NULL
)
4251 return (atoi(cp
+ 1));
4255 add_ni(const char *name
)
4260 for (pp
= &ni_list
; (p
= *pp
) != NULL
; pp
= &(p
->ni_next
)) {
4261 if (strcmp(p
->ni_name
, name
) == 0) {
4263 (void) fprintf(stderr
, "'%s' is a duplicate\n",
4270 (void) fprintf(stderr
, "adding '%s'\n",
4273 if ((p
= malloc(sizeof (ni_t
))) == NULL
)
4276 (void) strlcpy(p
->ni_name
, name
, sizeof (p
->ni_name
));
4284 ni_entry(const char *linkname
, void *arg
)
4287 datalink_class_t
class;
4289 (void) dladm_name2info(arg
, linkname
, NULL
, NULL
, &class, NULL
);
4291 if (class == DATALINK_CLASS_ETHERSTUB
)
4293 if (dlpi_open(linkname
, &dh
, 0) != DLPI_SUCCESS
)
4303 * dhcp-related routines
4307 setifdhcp(const char *caller
, const char *ifname
, int argc
, char *argv
[])
4309 dhcp_ipc_request_t
*request
;
4310 dhcp_ipc_reply_t
*reply
= NULL
;
4311 int timeout
= DHCP_IPC_WAIT_DEFAULT
;
4312 dhcp_ipc_type_t type
= DHCP_START
;
4314 boolean_t is_primary
= _B_FALSE
;
4315 boolean_t started
= _B_FALSE
;
4317 for (argv
++; --argc
> 0; argv
++) {
4319 if (strcmp(*argv
, "primary") == 0) {
4320 is_primary
= _B_TRUE
;
4324 if (strcmp(*argv
, "wait") == 0) {
4327 return (DHCP_EXIT_BADARGS
);
4331 if (strcmp(*argv
, "forever") == 0) {
4332 timeout
= DHCP_IPC_WAIT_FOREVER
;
4336 if (sscanf(*argv
, "%d", &timeout
) != 1) {
4338 return (DHCP_EXIT_BADARGS
);
4343 return (DHCP_EXIT_BADARGS
);
4348 type
= dhcp_string_to_request(*argv
);
4351 return (DHCP_EXIT_BADARGS
);
4356 * Only try to start agent on start or inform; in all other cases it
4357 * has to already be running for anything to make sense.
4359 if (type
== DHCP_START
|| type
== DHCP_INFORM
) {
4360 if (dhcp_start_agent(DHCP_IPC_MAX_WAIT
) == -1) {
4361 (void) fprintf(stderr
, "%s: unable to start %s\n",
4362 caller
, DHCP_AGENT_PATH
);
4363 return (DHCP_EXIT_FAILURE
);
4369 type
|= DHCP_PRIMARY
;
4374 request
= dhcp_ipc_alloc_request(type
, ifname
, NULL
, 0, DHCP_TYPE_NONE
);
4375 if (request
== NULL
) {
4376 (void) fprintf(stderr
, "%s: out of memory\n", caller
);
4377 return (DHCP_EXIT_SYSTEM
);
4380 error
= dhcp_ipc_make_request(request
, &reply
, timeout
);
4384 * Re-map connect error to not under control if we didn't try a
4385 * start operation, as this has to be true and results in a
4386 * clearer message, not to mention preserving compatibility
4387 * with the days when we always started dhcpagent for every
4390 if (error
== DHCP_IPC_E_CONNECT
&& !started
)
4391 error
= DHCP_IPC_E_UNKIF
;
4392 (void) fprintf(stderr
, "%s: %s: %s\n", caller
, ifname
,
4393 dhcp_ipc_strerror(error
));
4394 return (DHCP_EXIT_FAILURE
);
4397 error
= reply
->return_code
;
4402 if (error
== DHCP_IPC_E_TIMEOUT
&& timeout
== 0)
4403 return (DHCP_EXIT_SUCCESS
);
4405 (void) fprintf(stderr
, "%s: %s: %s\n", caller
, ifname
,
4406 dhcp_ipc_strerror(error
));
4408 if (error
== DHCP_IPC_E_TIMEOUT
)
4409 return (DHCP_EXIT_TIMEOUT
);
4411 return (DHCP_EXIT_IF_FAILURE
);
4414 if (DHCP_IPC_CMD(type
) == DHCP_STATUS
) {
4415 (void) printf("%s", dhcp_status_hdr_string());
4416 (void) printf("%s", dhcp_status_reply_to_string(reply
));
4421 return (DHCP_EXIT_SUCCESS
);
4427 (void) fprintf(stderr
,
4428 "usage: ifconfig <interface> | -a[ 4 | 6 | D ][ u | d ][ Z ]\n");
4430 (void) fprintf(stderr
, "%s",
4431 "\t[ <addr_family> ]\n"
4432 "\t[ <address>[/<prefix_length>] [ <dest_address> ] ]\n"
4433 "\t[ set [ <address>][/<prefix_length>] ]"
4434 " [ <address>/<prefix_length>] ]\n"
4435 "\t[ destination <dest_address> ]\n"
4436 "\t[ addif <address>[/<prefix_length>]"
4437 " [ <dest_address> ] ]\n"
4438 "\t[ removeif <address>[/<prefix_length>] ]\n"
4439 "\t[ arp | -arp ]\n"
4440 "\t[ auto-revarp ]\n"
4441 "\t[ broadcast <broad_addr> ]\n"
4442 "\t[ index <if_index> ]\n"
4443 "\t[ metric <n> ] [ mtu <n> ]\n"
4444 "\t[ netmask <mask> ]\n"
4445 "\t[ plumb ] [ unplumb ]\n"
4446 "\t[ preferred | -preferred ]\n"
4447 "\t[ private | -private ]\n"
4448 "\t[ local | -local ]\n"
4449 "\t[ router | -router ]\n"
4450 "\t[ subnet <subnet_address>]\n"
4451 "\t[ trailers | -trailers ]\n"
4452 "\t[ token <address>/<prefix_length> ]\n"
4453 "\t[ tsrc <tunnel_src_address> ]\n"
4454 "\t[ tdst <tunnel_dest_address> ]\n"
4455 "\t[ auth_algs <tunnel_AH_authentication_algorithm> ]\n"
4456 "\t[ encr_algs <tunnel_ESP_encryption_algorithm> ]\n"
4457 "\t[ encr_auth_algs <tunnel_ESP_authentication_algorithm> ]\n"
4458 "\t[ up ] [ down ]\n"
4459 "\t[ xmit | -xmit ]\n"
4461 "\t[ modinsert <module_name@position> ]\n"
4462 "\t[ modremove <module_name@position> ]\n"
4464 "\t[ group <groupname>] | [ group \"\"]\n"
4465 "\t[ deprecated | -deprecated ]\n"
4466 "\t[ standby | -standby ]\n"
4467 "\t[ failover | -failover ]\n"
4468 "\t[ zone <zonename> | -zone ]\n"
4469 "\t[ usesrc <interface> ]\n"
4470 "\t[ all-zones ]\n");
4472 (void) fprintf(stderr
, "or\n");
4473 (void) fprintf(stderr
,
4474 "\tifconfig <interface> | -a[ 4 | 6 | D ] [ u | d ]\n");
4476 (void) fprintf(stderr
, "%s", "\tauto-dhcp | dhcp\n"
4477 "\t[ wait <time> | forever ]\n\t[ primary ]\n"
4478 "\tstart | drop | ping | release | status | inform\n");