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 setifsrc(char *arg
, int64_t param
);
167 static int lifnum(const char *ifname
);
168 static void plumball(int, char **, int64_t, int64_t, int64_t);
171 * Address family specific function prototypes.
173 static void in_getaddr(char *s
, struct sockaddr
*saddr
, int *plenp
);
174 static void in_status(int force
, uint64_t flags
);
175 static void in_configinfo(int force
, uint64_t flags
);
176 static void in6_getaddr(char *s
, struct sockaddr
*saddr
, int *plenp
);
177 static void in6_status(int force
, uint64_t flags
);
178 static void in6_configinfo(int force
, uint64_t flags
);
181 * Misc support functions
183 static boolean_t
ni_entry(const char *, void *);
184 static void foreachinterface(int argc
, char *argv
[],
185 int af
, int64_t onflags
, int64_t offflags
,
187 static void ifconfig(int argc
, char *argv
[], int af
,
188 struct ifaddrs
*ifa
);
189 static boolean_t
in_getmask(struct sockaddr_in
*saddr
,
191 static int in_getprefixlen(char *addr
, boolean_t slash
, int plen
);
192 static boolean_t
in_prefixlentomask(int prefixlen
, int maxlen
,
194 static void status(void);
195 static void ifstatus(const char *ifname
);
196 static void tun_status(datalink_id_t
);
197 static void usage(void);
198 static int setifdhcp(const char *caller
, const char *ifname
,
199 int argc
, char *argv
[]);
200 static int ip_domux2fd(int *, int *, int *, int *, int *);
201 static int ip_plink(int, int, int, int, int);
202 static int modop(char *arg
, char op
);
203 static int find_all_interfaces(struct lifconf
*lifcp
, char **buf
,
205 static int create_ipmp(const char *grname
, int af
,
206 const char *ifname
, boolean_t implicit
);
207 static void start_ipmp_daemon(void);
208 static boolean_t
ifaddr_up(ifaddrlistx_t
*ifaddrp
);
209 static boolean_t
ifaddr_down(ifaddrlistx_t
*ifaddrp
);
210 static dladm_status_t
ifconfig_dladm_open(const char *, datalink_class_t
,
212 static void dladmerr_exit(dladm_status_t status
, const char *str
);
213 static void ipadmerr_exit(ipadm_status_t status
, const char *str
);
214 static boolean_t
ifconfig_use_libipadm(int, const char *);
216 #define max(a, b) ((a) < (b) ? (b) : (a))
219 * DHCP_EXIT_IF_FAILURE indicates that the operation failed, but if there
220 * are more interfaces to act on (i.e., ifconfig was invoked with -a), keep
221 * on going rather than exit with an error.
224 #define DHCP_EXIT_IF_FAILURE -1
226 #define NEXTARG 0xffffff /* command takes an argument */
227 #define OPTARG 0xfffffe /* command takes an optional argument */
230 /* Refer to the comments in ifconfig() on the netmask "hack" */
231 #define NETMASK_CMD "netmask"
232 struct sockaddr_storage g_netmask
;
233 enum { G_NETMASK_NIL
, G_NETMASK_PENDING
, G_NETMASK_SET
}
234 g_netmask_set
= G_NETMASK_NIL
;
238 int64_t c_parameter
; /* NEXTARG means next argv */
239 int (*c_func
)(char *, int64_t);
240 int c_abortonfail
; /* don't continue parsing args */
241 /* for the current interface */
242 int c_af
; /* address family restrictions */
244 { "up", IFF_UP
, setifflags
, 0, AF_ANY
},
245 { "down", -IFF_UP
, setifflags
, 0, AF_ANY
},
246 { "trailers", -IFF_NOTRAILERS
, setifflags
, 0, AF_ANY
},
247 { "-trailers", IFF_NOTRAILERS
, setifflags
, 0, AF_ANY
},
248 { "arp", -IFF_NOARP
, setifflags
, 0, AF_INET
},
249 { "-arp", IFF_NOARP
, setifflags
, 0, AF_INET
},
250 { "router", IFF_ROUTER
, setifflags
, 0, AF_ANY
},
251 { "-router", -IFF_ROUTER
, setifflags
, 0, AF_ANY
},
252 { "private", IFF_PRIVATE
, setifflags
, 0, AF_ANY
},
253 { "-private", -IFF_PRIVATE
, setifflags
, 0, AF_ANY
},
254 { "xmit", -IFF_NOXMIT
, setifflags
, 0, AF_ANY
},
255 { "-xmit", IFF_NOXMIT
, setifflags
, 0, AF_ANY
},
256 { "-nud", IFF_NONUD
, setifflags
, 0, AF_INET6
},
257 { "nud", -IFF_NONUD
, setifflags
, 0, AF_INET6
},
258 { "anycast", IFF_ANYCAST
, setifflags
, 0, AF_ANY
},
259 { "-anycast", -IFF_ANYCAST
, setifflags
, 0, AF_ANY
},
260 { "local", -IFF_NOLOCAL
, setifflags
, 0, AF_ANY
},
261 { "-local", IFF_NOLOCAL
, setifflags
, 0, AF_ANY
},
262 { "deprecated", IFF_DEPRECATED
, setifflags
, 0, AF_ANY
},
263 { "-deprecated", -IFF_DEPRECATED
, setifflags
, 0, AF_ANY
},
264 { "preferred", IFF_PREFERRED
, setifflags
, 0, AF_INET6
},
265 { "-preferred", -IFF_PREFERRED
, setifflags
, 0, AF_INET6
},
266 { "debug", 0, setdebugflag
, 0, AF_ANY
},
267 { "verbose", 0, setverboseflag
, 0, AF_ANY
},
268 { NETMASK_CMD
, NEXTARG
, setifnetmask
, 0, AF_INET
},
269 { "metric", NEXTARG
, setifmetric
, 0, AF_ANY
},
270 { "mtu", NEXTARG
, setifmtu
, 0, AF_ANY
},
271 { "index", NEXTARG
, setifindex
, 0, AF_ANY
},
272 { "broadcast", NEXTARG
, setifbroadaddr
, 0, AF_INET
},
273 { "auto-revarp", 0, setifrevarp
, 1, AF_INET
},
274 { "ipmp", 0, inetipmp
, 1, AF_ANY
},
275 { "plumb", 0, inetplumb
, 1, AF_ANY
},
276 { "unplumb", 0, inetunplumb
, 0, AF_ANY
},
277 { "subnet", NEXTARG
, setifsubnet
, 0, AF_ANY
},
278 { "token", NEXTARG
, setiftoken
, 0, AF_INET6
},
279 { "tsrc", NEXTARG
, setiftsrc
, 0, AF_ANY
},
280 { "tdst", NEXTARG
, setiftdst
, 0, AF_ANY
},
281 { "encr_auth_algs", NEXTARG
, set_tun_esp_auth_alg
, 0, AF_ANY
},
282 { "encr_algs", NEXTARG
, set_tun_esp_encr_alg
, 0, AF_ANY
},
283 { "auth_algs", NEXTARG
, set_tun_ah_alg
, 0, AF_ANY
},
284 { "addif", NEXTARG
, addif
, 1, AF_ANY
},
285 { "removeif", NEXTARG
, removeif
, 1, AF_ANY
},
286 { "modlist", 0, modlist
, 1, AF_ANY
},
287 { "modinsert", NEXTARG
, modinsert
, 1, AF_ANY
},
288 { "modremove", NEXTARG
, modremove
, 1, AF_ANY
},
289 { "failover", -IFF_NOFAILOVER
, setifflags
, 1, AF_ANY
},
290 { "-failover", IFF_NOFAILOVER
, setifflags
, 1, AF_ANY
},
291 { "standby", IFF_STANDBY
, setifflags
, 1, AF_ANY
},
292 { "-standby", -IFF_STANDBY
, setifflags
, 1, AF_ANY
},
293 { "failed", IFF_FAILED
, setifflags
, 1, AF_ANY
},
294 { "-failed", -IFF_FAILED
, setifflags
, 1, AF_ANY
},
295 { "group", NEXTARG
, setifgroupname
, 1, AF_ANY
},
296 { "configinfo", 0, configinfo
, 1, AF_ANY
},
297 { "encaplimit", NEXTARG
, set_tun_encap_limit
, 0, AF_ANY
},
298 { "-encaplimit", 0, clr_tun_encap_limit
, 0, AF_ANY
},
299 { "thoplimit", NEXTARG
, set_tun_hop_limit
, 0, AF_ANY
},
300 { "set", NEXTARG
, setifaddr
, 0, AF_ANY
},
301 { "destination", NEXTARG
, setifdstaddr
, 0, AF_ANY
},
302 { "zone", NEXTARG
, setzone
, 0, AF_ANY
},
303 { "-zone", 0, setzone
, 0, AF_ANY
},
304 { "ether", OPTARG
, setifether
, 0, AF_ANY
},
305 { "usesrc", NEXTARG
, setifsrc
, 0, AF_ANY
},
308 * NOTE: any additions to this table must also be applied to ifparse
309 * (usr/src/cmd/cmd-inet/sbin/ifparse/ifparse.c)
312 { 0, 0, setifaddr
, 0, AF_ANY
},
313 { 0, 0, setifdstaddr
, 0, AF_ANY
},
318 typedef struct if_config_cmd
{
325 * NOTE: print_config_flags() processes this table in order, so we put "up"
326 * last so that we can be sure "-failover" will take effect first. Otherwise,
327 * IPMP test addresses will erroneously migrate to the IPMP interface.
329 static if_config_cmd_t if_config_cmd_tbl
[] = {
330 { IFF_NOTRAILERS
, AF_UNSPEC
, "-trailers" },
331 { IFF_PRIVATE
, AF_UNSPEC
, "private" },
332 { IFF_NOXMIT
, AF_UNSPEC
, "-xmit" },
333 { IFF_ANYCAST
, AF_INET6
, "anycast" },
334 { IFF_NOLOCAL
, AF_UNSPEC
, "-local" },
335 { IFF_DEPRECATED
, AF_UNSPEC
, "deprecated" },
336 { IFF_NOFAILOVER
, AF_UNSPEC
, "-failover" },
337 { IFF_STANDBY
, AF_UNSPEC
, "standby" },
338 { IFF_FAILED
, AF_UNSPEC
, "failed" },
339 { IFF_PREFERRED
, AF_UNSPEC
, "preferred" },
340 { IFF_NONUD
, AF_INET6
, "-nud" },
341 { IFF_NOARP
, AF_INET
, "-arp" },
342 { IFF_UP
, AF_UNSPEC
, "up" },
347 char ni_name
[LIFNAMSIZ
];
351 static ni_t
*ni_list
= NULL
;
352 static int num_ni
= 0;
354 /* End defines and structure definitions for ifconfig -a plumb */
356 /* Known address families */
361 void (*af_getaddr
)();
362 void (*af_configinfo
)();
364 { "inet", AF_INET
, in_status
, in_getaddr
, in_configinfo
},
365 { "inet6", AF_INET6
, in6_status
, in6_getaddr
, in6_configinfo
},
369 #define SOCKET_AF(af) (((af) == AF_UNSPEC) ? AF_INET : (af))
371 struct afswtch
*afp
; /* the address family being set or asked about */
374 main(int argc
, char *argv
[])
377 char *default_ip_str
;
378 ipadm_status_t istatus
;
380 lifc_flags
= LIFC_DEFAULT
;
383 (void) strncpy(name
, "-a", sizeof (name
));
386 if (strlen(*argv
) > sizeof (name
) - 1) {
387 (void) fprintf(stderr
, "%s: interface name too long\n",
391 (void) strncpy(name
, *argv
, sizeof (name
));
393 name
[sizeof (name
) - 1] = '\0';
394 (void) strncpy(origname
, name
, sizeof (origname
)); /* For addif */
395 default_ip_str
= NULL
;
396 v4compat
= get_compat_flag(&default_ip_str
);
397 if (v4compat
== DEFAULT_PROT_BAD_VALUE
) {
398 (void) fprintf(stderr
,
399 "ifconfig: %s: Bad value for %s in %s\n", default_ip_str
,
400 DEFAULT_IP
, INET_DEFAULT_FILE
);
401 free(default_ip_str
);
404 free(default_ip_str
);
407 struct afswtch
*myafp
;
409 for (myafp
= afp
= afs
; myafp
->af_name
; myafp
++) {
410 if (strcmp(myafp
->af_name
, *argv
) == 0) {
411 afp
= myafp
; argc
--; argv
++;
415 af
= lifr
.lifr_addr
.ss_family
= afp
->af_af
;
416 if (af
== AF_INET6
) {
421 s
= socket(SOCKET_AF(af
), SOCK_DGRAM
, 0);
422 s4
= socket(AF_INET
, SOCK_DGRAM
, 0);
423 s6
= socket(AF_INET6
, SOCK_DGRAM
, 0);
424 if (s
== -1 || s4
== -1 || s6
== -1)
425 Perror0_exit("socket");
427 * Open the global libipadm handle. The flag IPH_LEGACY has to
428 * be specified to indicate that logical interface names will
429 * be used during interface creation and address creation.
431 if ((istatus
= ipadm_open(&iph
, IPH_LEGACY
)) != IPADM_SUCCESS
)
432 ipadmerr_exit(istatus
, "unable to open handle to libipadm");
435 * Special interface names is any combination of these flags.
436 * Note that due to the ifconfig syntax they have to be combined
437 * as a single '-' option.
440 * -d "down" interfaces
441 * -D Interfaces not controlled by DHCP
444 * -X Turn on debug (not documented)
446 * -Z Only interfaces in caller's zone
449 if (name
[0] == '-') {
450 /* One or more options */
452 int64_t offflags
= 0;
454 char *av
[2] = { "ifconfig", name
};
456 while ((c
= getopt(2, av
, "audhDXZ46v")) != -1) {
468 offflags
|= IFF_DHCPRUNNING
;
474 lifc_flags
&= ~LIFC_ALLZONES
;
478 * -4 is not a compatable flag, therefore
479 * we assume they want v4compat turned off
486 * If they want IPv6, well then we'll assume
487 * they don't want IPv4 compat
502 (void) fprintf(stderr
,
503 "ifconfig: %s: no such interface\n", name
);
506 foreachinterface(argc
, argv
, af
, onflags
, offflags
,
509 ifconfig(argc
, argv
, af
, NULL
);
516 * For each interface, call ifconfig(argc, argv, af, ifa).
517 * Only call function if onflags and offflags are set or clear, respectively,
518 * in the interfaces flags field.
521 foreachinterface(int argc
, char *argv
[], int af
,
522 int64_t onflags
, int64_t offflags
, int64_t lifc_flags
)
524 ipadm_addr_info_t
*ainfo
, *ainfop
;
526 ipadm_status_t istatus
;
530 * ifconfig -a plumb should find all network interfaces in the current
533 if (argc
> 0 && (strcmp(*argv
, "plumb") == 0)) {
534 plumball(argc
, argv
, onflags
, offflags
, lifc_flags
);
537 /* Get all addresses in kernel including addresses that are zero. */
538 istatus
= ipadm_addr_info(iph
, NULL
, &ainfo
, IPADM_OPT_ZEROADDR
,
540 if (istatus
!= IPADM_SUCCESS
)
541 ipadmerr_exit(istatus
, "could not get addresses from kernel");
544 * For each logical interface, call ifconfig() with the
547 for (ainfop
= ainfo
; ainfop
!= NULL
; ainfop
= IA_NEXT(ainfop
)) {
548 if (ainfop
->ia_state
== IFA_DISABLED
)
550 ifa
= &ainfop
->ia_ifa
;
551 if (onflags
|| offflags
) {
552 if ((ifa
->ifa_flags
& onflags
) != onflags
)
554 if ((~ifa
->ifa_flags
& offflags
) != offflags
)
557 s
= (ifa
->ifa_addr
->sa_family
== AF_INET
? s4
: s6
);
558 (void) strncpy(name
, ifa
->ifa_name
, sizeof (name
));
559 (void) strncpy(origname
, name
, sizeof (origname
));
560 ifconfig(argc
, argv
, af
, ifa
);
562 ipadm_free_addr_info(ainfo
);
566 * Used for `ifconfig -a plumb'. Finds all datalinks and plumbs the interface.
569 plumball(int argc
, char *argv
[], int64_t onflags
, int64_t offflags
,
573 struct lifreq
*lifrp
;
577 if (onflags
!= 0 || offflags
!= 0) {
578 (void) fprintf(stderr
, "ifconfig: invalid syntax used to "
579 "plumb all interfaces.\n");
583 if (find_all_interfaces(&lifc
, &buf
, lifc_flags
) != 0 ||
587 lifrp
= lifc
.lifc_req
;
588 for (n
= lifc
.lifc_len
/ sizeof (struct lifreq
); n
> 0; n
--, lifrp
++) {
591 * setaddr: Used by parser to tear apart source and dest
592 * name and origname contain the name of the 'current'
596 (void) strncpy(name
, lifrp
->lifr_name
, sizeof (name
));
597 (void) strncpy(origname
, name
, sizeof (origname
));
598 ifconfig(argc
, argv
, af
, NULL
);
603 * Parses the interface name and the command in argv[]. Calls the
604 * appropriate callback function for the given command from `cmds[]'
606 * If there is no command specified, it prints all addresses.
609 ifconfig(int argc
, char *argv
[], int af
, struct ifaddrs
*ifa
)
611 static boolean_t scan_netmask
= _B_FALSE
;
613 ipadm_status_t istatus
;
621 if (strcmp(*argv
, "auto-dhcp") == 0 || strcmp(*argv
, "dhcp") == 0) {
623 * Some errors are ignored in the case where more than one
624 * interface is being operated on.
626 ret
= setifdhcp("ifconfig", name
, argc
, argv
);
627 if (ret
== DHCP_EXIT_IF_FAILURE
) {
629 exit(DHCP_EXIT_FAILURE
);
630 } else if (ret
!= DHCP_EXIT_SUCCESS
) {
637 * The following is a "hack" to get around the existing interface
638 * setting mechanism. Currently, each interface attribute,
639 * such as address, netmask, broadcast, ... is set separately. But
640 * sometimes two or more attributes must be set together. For
641 * example, setting an address without a netmask does not make sense.
642 * Yet they can be set separately for IPv4 address using the current
643 * ifconfig(1M) syntax. The kernel then "infers" the correct netmask
644 * using the deprecated "IP address classes." This is simply not
647 * The "hack" below is to go thru the whole command list looking for
648 * the netmask command first. Then use this netmask to set the
649 * address. This does not provide an extensible way to accommodate
650 * future need for setting more than one attributes together.
652 * Note that if the "netmask" command argument is a "+", we need
653 * to save this info and do the query after we know the address to
654 * be set. The reason is that if "addif" is used, the working
655 * interface name will be changed later when the logical interface
656 * is created. In in_getmask(), if an address is not provided,
657 * it will use the working interface's address to do the query.
658 * It will be wrong now as we don't know the logical interface's name.
660 * ifconfig(1M) is too overloaded and the code is so convoluted
661 * that it is "safer" not to re-architect the code to fix the above
662 * issue, hence this "hack." We may be better off to have a new
663 * command with better syntax for configuring network interface
666 if (!scan_netmask
&& afp
->af_af
== AF_INET
) {
670 /* Only go thru the command list once to find the netmask. */
671 scan_netmask
= _B_TRUE
;
674 * Currently, if multiple netmask commands are specified, the
675 * last one will be used as the final netmask. So we need
676 * to scan the whole list to preserve this behavior.
678 for (largc
= argc
, largv
= argv
; largc
> 0; largc
--, largv
++) {
679 if (strcmp(*largv
, NETMASK_CMD
) == 0) {
683 if (strcmp(*largv
, "+") == 0) {
684 g_netmask_set
= G_NETMASK_PENDING
;
686 in_getaddr(*largv
, (struct sockaddr
*)
688 g_netmask_set
= G_NETMASK_SET
;
690 /* Continue the scan. */
700 (void) printf("ifconfig: argv %s\n", *argv
);
702 found_cmd
= _B_FALSE
;
703 for (p
= cmds
; p
->c_func
; p
++) {
705 if (strcmp(*argv
, p
->c_name
) == 0) {
707 * indicate that the command was
708 * found and check to see if
709 * the address family is valid
712 if (p
->c_af
== AF_ANY
||
717 if (p
->c_af
== AF_ANY
||
723 * If we found the keyword, but the address family
724 * did not match spit out an error
726 if (found_cmd
&& p
->c_name
== 0) {
727 (void) fprintf(stderr
, "ifconfig: Operation %s not"
728 " supported for %s\n", *argv
, afp
->af_name
);
732 * else (no keyword found), we assume it's an address
735 if (setaddr
&& ipaddr
!= NULL
) {
737 * We must have already filled in a source address in
738 * `ipaddr' and we now got a destination address.
739 * Fill it in `ipaddr' and call libipadm to create
740 * the static address.
742 if (p
->c_name
== 0) {
743 istatus
= ipadm_set_dst_addr(ipaddr
, *argv
,
744 (p
->c_af
== AF_ANY
? AF_UNSPEC
: af
));
745 if (istatus
!= IPADM_SUCCESS
) {
746 ipadmerr_exit(istatus
, "could not "
747 "set destination address");
750 * finished processing dstaddr, so reset setaddr
755 * Both source and destination address are in `ipaddr'.
756 * Add the address by calling libipadm.
758 istatus
= ipadm_create_addr(iph
, ipaddr
,
760 if (istatus
!= IPADM_SUCCESS
)
762 ipadm_destroy_addrobj(ipaddr
);
764 setaddr_done
= _B_TRUE
;
765 if (p
->c_name
== 0) {
766 /* move parser along */
771 if (p
->c_name
== 0 && setaddr_done
) {
773 * catch odd commands like
774 * "ifconfig <intf> addr1 addr2 addr3 addr4 up"
776 (void) fprintf(stderr
, "%s",
777 "ifconfig: cannot configure more than two "
778 "addresses in one command\n");
782 if (p
->c_af
== AF_INET6
) {
785 if (p
->c_parameter
== NEXTARG
||
786 p
->c_parameter
== OPTARG
) {
788 if (argc
== 0 && p
->c_parameter
== NEXTARG
) {
789 (void) fprintf(stderr
,
790 "ifconfig: no argument for %s\n",
796 * Call the function if:
798 * there's no address family
801 * we don't know the address yet
802 * (because we were called from
805 * there is a restriction AND
806 * the address families match
808 if ((p
->c_af
== AF_ANY
) ||
810 (ifa
->ifa_addr
->sa_family
== p
->c_af
)) {
811 ret
= (*p
->c_func
)(*argv
, p
->c_parameter
);
813 * If c_func failed and we should
814 * abort processing for this
815 * interface on failure, return
816 * now rather than going on to
817 * process other commands for
818 * the same interface.
820 if (ret
!= 0 && p
->c_abortonfail
)
827 if (setaddr
&& ipaddr
!= NULL
) {
829 * Only the source address was provided, which was already
830 * set in `ipaddr'. Add the address by calling libipadm.
832 istatus
= ipadm_create_addr(iph
, ipaddr
, IPADM_OPT_ACTIVE
);
833 if (istatus
!= IPADM_SUCCESS
)
835 ipadm_destroy_addrobj(ipaddr
);
837 setaddr_done
= _B_TRUE
;
840 /* Check to see if there's a security hole in the tunnel setup. */
841 if (ipsec_policy_set
&& !ipsec_auth_covered
) {
842 (void) fprintf(stderr
, "ifconfig: WARNING: tunnel with only "
843 "ESP and no authentication.\n");
848 (void) fprintf(stderr
, "ifconfig: could not create address:% s\n",
849 ipadm_status2str(istatus
));
850 /* Remove the newly created logical interface. */
851 if (strcmp(name
, origname
) != 0) {
852 assert(strchr(name
, ':') != NULL
);
853 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
854 (void) ioctl(s
, SIOCLIFREMOVEIF
, (caddr_t
)&lifr
);
861 setdebugflag(char *val
, int64_t arg
)
869 setverboseflag(char *val
, int64_t arg
)
876 * This function fills in the given lifreq's lifr_addr field based on
880 set_mask_lifreq(struct lifreq
*lifr
, struct sockaddr_storage
*addr
,
881 struct sockaddr_storage
*mask
)
883 assert(addr
!= NULL
);
884 assert(mask
!= NULL
);
886 switch (g_netmask_set
) {
888 lifr
->lifr_addr
= g_netmask
;
891 case G_NETMASK_PENDING
:
893 * "+" is used as the argument to "netmask" command. Query
894 * the database on the correct netmask based on the address to
897 assert(afp
->af_af
== AF_INET
);
899 if (!in_getmask((struct sockaddr_in
*)&g_netmask
, _B_TRUE
)) {
900 lifr
->lifr_addr
= *mask
;
901 g_netmask_set
= G_NETMASK_NIL
;
903 lifr
->lifr_addr
= g_netmask
;
904 g_netmask_set
= G_NETMASK_SET
;
910 lifr
->lifr_addr
= *mask
;
916 * Set the interface address. Handles <addr>, <addr>/<n> as well as /<n>
917 * syntax for setting the address, the address plus netmask, and just
918 * the netmask respectively.
922 setifaddr(char *addr
, int64_t param
)
924 ipadm_status_t istatus
;
927 struct sockaddr_storage laddr
;
928 struct sockaddr_storage netmask
;
929 struct sockaddr_in6
*sin6
;
930 struct sockaddr_in
*sin
;
931 struct sockaddr_storage sav_netmask
;
932 char cidraddr
[BUFSIZ
];
935 return (setifprefixlen(addr
, 0));
937 (*afp
->af_getaddr
)(addr
, (struct sockaddr
*)&laddr
, &prefixlen
);
939 (void) memset(&netmask
, 0, sizeof (netmask
));
940 netmask
.ss_family
= afp
->af_af
;
943 /* Nothing there - ok */
946 (void) fprintf(stderr
, "ifconfig: Bad prefix length in %s\n",
950 if (afp
->af_af
== AF_INET6
) {
951 sin6
= (struct sockaddr_in6
*)&netmask
;
952 if (!in_prefixlentomask(prefixlen
, IPV6_ABITS
,
953 (uchar_t
*)&sin6
->sin6_addr
)) {
954 (void) fprintf(stderr
, "ifconfig: "
955 "Bad prefix length: %d\n",
960 sin
= (struct sockaddr_in
*)&netmask
;
961 if (!in_prefixlentomask(prefixlen
, IP_ABITS
,
962 (uchar_t
*)&sin
->sin_addr
)) {
963 (void) fprintf(stderr
, "ifconfig: "
964 "Bad prefix length: %d\n",
970 * Just in case of funny setting of both prefix and netmask,
971 * prefix should override the netmask command.
973 g_netmask_set
= G_NETMASK_NIL
;
978 * Check and see if any "netmask" command is used and perform the
979 * necessary operation.
981 set_mask_lifreq(&lifr
, &laddr
, &netmask
);
983 /* This check is temporary until libipadm supports IPMP interfaces. */
984 if (ifconfig_use_libipadm(s
, name
)) {
985 char addrstr
[INET6_ADDRSTRLEN
];
988 sin
= (struct sockaddr_in
*)&laddr
;
989 (void) inet_ntop(AF_INET
, &sin
->sin_addr
, addrstr
,
992 sin6
= (struct sockaddr_in6
*)&laddr
;
993 (void) inet_ntop(AF_INET6
, &sin6
->sin6_addr
, addrstr
,
996 istatus
= ipadm_create_addrobj(IPADM_ADDR_STATIC
, name
,
998 if (istatus
!= IPADM_SUCCESS
)
999 ipadmerr_exit(istatus
, "setifaddr");
1002 * lifr.lifr_addr, which is updated by set_mask_lifreq()
1003 * will contain the right mask to use.
1005 prefixlen
= mask2plen((struct sockaddr
*)&lifr
.lifr_addr
);
1006 (void) snprintf(cidraddr
, sizeof (cidraddr
), "%s/%d",
1007 addrstr
, prefixlen
);
1009 istatus
= ipadm_set_addr(ipaddr
, cidraddr
, af
);
1010 if (istatus
!= IPADM_SUCCESS
)
1011 ipadmerr_exit(istatus
, "could not set address");
1013 * let parser know we got a source.
1014 * Next address, if given, should be dest
1019 * address will be set by the parser after nextarg has
1025 /* Tell parser that an address was set */
1027 /* save copy of netmask to restore in case of error */
1028 (void) strncpy(lifr1
.lifr_name
, name
, sizeof (lifr1
.lifr_name
));
1029 if (ioctl(s
, SIOCGLIFNETMASK
, (caddr_t
)&lifr1
) < 0)
1030 Perror0_exit("SIOCGLIFNETMASK");
1031 sav_netmask
= lifr1
.lifr_addr
;
1034 * If setting the address and not the mask, clear any existing mask
1035 * and the kernel will then assign the default (netmask has been set
1036 * to 0 in this case). If setting both (either by using a prefix or
1037 * using the netmask command), set the mask first, so the address will
1038 * be interpreted correctly.
1040 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1041 /* lifr.lifr_addr already contains netmask from set_mask_lifreq() */
1042 if (ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
) < 0)
1043 Perror0_exit("SIOCSLIFNETMASK");
1046 char abuf
[INET6_ADDRSTRLEN
];
1047 void *addr
= (afp
->af_af
== AF_INET
) ?
1048 (void *)&((struct sockaddr_in
*)&laddr
)->sin_addr
:
1049 (void *)&((struct sockaddr_in6
*)&laddr
)->sin6_addr
;
1051 (void) printf("Setting %s af %d addr %s\n",
1052 lifr
.lifr_name
, afp
->af_af
,
1053 inet_ntop(afp
->af_af
, addr
, abuf
, sizeof (abuf
)));
1055 lifr
.lifr_addr
= laddr
;
1056 lifr
.lifr_addr
.ss_family
= afp
->af_af
;
1057 if (ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
) < 0) {
1059 * Restore the netmask
1063 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1064 lifr
.lifr_addr
= sav_netmask
;
1065 (void) ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
);
1067 Perror0_exit("SIOCSLIFADDR");
1074 * The following functions are stolen from the ipseckey(1m) program.
1075 * Perhaps they should be somewhere common, but for now, we just maintain
1076 * two versions. We do this because of the different semantics for which
1077 * algorithms we select ("requested" for ifconfig vs. "actual" for key).
1087 rc
= strtoul(num
, &end
, 0);
1088 if (errno
!= 0 || end
== num
|| *end
!= '\0') {
1096 * Parse and reverse parse possible algorithm values, include numbers.
1097 * Mostly stolen from ipseckey.c. See the comments above parsenum() for why
1098 * this isn't common to ipseckey.c.
1100 * NOTE: Static buffer in this function for the return value. Since ifconfig
1101 * isn't multithreaded, this isn't a huge problem.
1104 #define NBUF_SIZE 20 /* Enough to print a large integer. */
1107 rparsealg(uint8_t alg_value
, int proto_num
)
1109 struct ipsecalgent
*alg
;
1110 static char numprint
[128]; /* Enough to hold an algorithm name. */
1113 * Special cases for "any" and "none"
1114 * The kernel needs to be able to distinguish between "any"
1115 * and "none" and the APIs are underdefined in this area for auth.
1117 if (proto_num
== IPSEC_PROTO_AH
) {
1118 if (alg_value
== SADB_AALG_NONE
)
1120 if (alg_value
== SADB_AALG_ANY
)
1124 alg
= getipsecalgbynum(alg_value
, proto_num
, NULL
);
1126 (void) strlcpy(numprint
, alg
->a_names
[0], sizeof (numprint
));
1127 freeipsecalgent(alg
);
1129 (void) snprintf(numprint
, sizeof (numprint
), "%d", alg_value
);
1136 parsealg(char *algname
, int proto_num
)
1138 struct ipsecalgent
*alg
;
1141 if (algname
== NULL
) {
1142 (void) fprintf(stderr
, "ifconfig: Unexpected end of command "
1148 * Special-case "none" and "any".
1149 * Use strcasecmp because its length is bounded.
1151 if (strcasecmp("none", algname
) == 0) {
1152 return ((proto_num
== IPSEC_PROTO_ESP
) ?
1153 NO_ESP_EALG
: NO_ESP_AALG
);
1155 if ((strcasecmp("any", algname
) == 0) && (proto_num
== IPSEC_PROTO_AH
))
1156 return (SADB_AALG_ANY
);
1158 alg
= getipsecalgbyname(algname
, proto_num
, NULL
);
1160 invalue
= alg
->a_alg_num
;
1161 freeipsecalgent(alg
);
1162 return ((uint_t
)invalue
);
1166 * Since algorithms can be loaded during kernel run-time, check for
1167 * numeric algorithm values too.
1169 invalue
= parsenum(algname
);
1170 if ((invalue
& (ulong_t
)0xff) == invalue
)
1171 return ((uint_t
)invalue
);
1173 (void) fprintf(stderr
, "ifconfig: %s algorithm type %s unknown.\n",
1174 (proto_num
== IPSEC_PROTO_ESP
) ?
1175 "Encryption" : "Authentication", algname
);
1181 * Actual ifconfig functions to set tunnel security properties.
1184 enum ipsec_alg_type
{ ESP_ENCR_ALG
= 1, ESP_AUTH_ALG
, AH_AUTH_ALG
};
1187 set_tun_algs(int which_alg
, int alg
)
1189 boolean_t encr_alg_set
= _B_FALSE
;
1190 iptun_params_t params
;
1191 dladm_status_t status
;
1194 if ((status
= ifconfig_dladm_open(name
, DATALINK_CLASS_IPTUN
,
1195 ¶ms
.iptun_param_linkid
)) != DLADM_STATUS_OK
)
1198 status
= dladm_iptun_getparams(dlh
, ¶ms
, DLADM_OPT_ACTIVE
);
1199 if (status
!= DLADM_STATUS_OK
)
1202 ipsr
= ¶ms
.iptun_param_secinfo
;
1205 * If I'm just starting off this ifconfig, I want a clean slate,
1206 * otherwise, I've captured the current tunnel security settings.
1207 * In the case of continuation, I merely add to the settings.
1209 if (!(params
.iptun_param_flags
& IPTUN_PARAM_SECINFO
))
1210 (void) memset(ipsr
, 0, sizeof (*ipsr
));
1212 /* We're only modifying the IPsec information */
1213 params
.iptun_param_flags
= IPTUN_PARAM_SECINFO
;
1215 switch (which_alg
) {
1217 if (alg
== NO_ESP_EALG
) {
1218 if (ipsr
->ipsr_esp_auth_alg
== SADB_AALG_NONE
)
1219 ipsr
->ipsr_esp_req
= 0;
1220 ipsr
->ipsr_esp_alg
= SADB_EALG_NONE
;
1222 /* Let the user specify NULL encryption implicitly. */
1223 if (ipsr
->ipsr_esp_auth_alg
!= SADB_AALG_NONE
) {
1224 encr_alg_set
= _B_TRUE
;
1225 ipsr
->ipsr_esp_alg
= SADB_EALG_NULL
;
1228 encr_alg_set
= _B_TRUE
;
1229 ipsr
->ipsr_esp_req
=
1230 IPSEC_PREF_REQUIRED
| IPSEC_PREF_UNIQUE
;
1231 ipsr
->ipsr_esp_alg
= alg
;
1235 if (alg
== NO_ESP_AALG
) {
1236 if ((ipsr
->ipsr_esp_alg
== SADB_EALG_NONE
||
1237 ipsr
->ipsr_esp_alg
== SADB_EALG_NULL
) &&
1239 ipsr
->ipsr_esp_req
= 0;
1240 ipsr
->ipsr_esp_auth_alg
= SADB_AALG_NONE
;
1242 ipsr
->ipsr_esp_req
=
1243 IPSEC_PREF_REQUIRED
| IPSEC_PREF_UNIQUE
;
1244 ipsr
->ipsr_esp_auth_alg
= alg
;
1246 /* Let the user specify NULL encryption implicitly. */
1247 if (ipsr
->ipsr_esp_alg
== SADB_EALG_NONE
&&
1249 ipsr
->ipsr_esp_alg
= SADB_EALG_NULL
;
1253 if (alg
== NO_AH_AALG
) {
1254 ipsr
->ipsr_ah_req
= 0;
1255 ipsr
->ipsr_auth_alg
= SADB_AALG_NONE
;
1258 IPSEC_PREF_REQUIRED
| IPSEC_PREF_UNIQUE
;
1259 ipsr
->ipsr_auth_alg
= alg
;
1262 /* Will never hit DEFAULT */
1265 status
= dladm_iptun_modify(dlh
, ¶ms
, DLADM_OPT_ACTIVE
);
1268 if (status
!= DLADM_STATUS_OK
)
1269 dladmerr_exit(status
, name
);
1271 ipsec_policy_set
= _B_TRUE
;
1272 if ((ipsr
->ipsr_esp_req
!= 0 &&
1273 ipsr
->ipsr_esp_auth_alg
!= SADB_AALG_NONE
) ||
1274 (ipsr
->ipsr_ah_req
!= 0 &&
1275 ipsr
->ipsr_auth_alg
!= SADB_AALG_NONE
))
1276 ipsec_auth_covered
= _B_TRUE
;
1283 set_tun_esp_encr_alg(char *addr
, int64_t param
)
1285 return (set_tun_algs(ESP_ENCR_ALG
,
1286 parsealg(addr
, IPSEC_PROTO_ESP
)));
1291 set_tun_esp_auth_alg(char *addr
, int64_t param
)
1293 return (set_tun_algs(ESP_AUTH_ALG
,
1294 parsealg(addr
, IPSEC_PROTO_AH
)));
1299 set_tun_ah_alg(char *addr
, int64_t param
)
1301 return (set_tun_algs(AH_AUTH_ALG
,
1302 parsealg(addr
, IPSEC_PROTO_AH
)));
1307 setifrevarp(char *arg
, int64_t param
)
1309 struct sockaddr_in laddr
;
1311 if (afp
->af_af
== AF_INET6
) {
1312 (void) fprintf(stderr
,
1313 "ifconfig: revarp not possible on IPv6 interface %s\n",
1317 if (doifrevarp(name
, &laddr
)) {
1318 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1319 laddr
.sin_family
= AF_INET
;
1320 (void) memcpy(&lifr
.lifr_addr
, &laddr
, sizeof (laddr
));
1321 if (ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
) < 0)
1322 Perror0_exit("SIOCSLIFADDR");
1329 setifsubnet(char *addr
, int64_t param
)
1332 struct sockaddr_storage subnet
;
1334 (*afp
->af_getaddr
)(addr
, &subnet
, &prefixlen
);
1336 switch (prefixlen
) {
1338 (void) fprintf(stderr
,
1339 "ifconfig: Missing prefix length in subnet %s\n", addr
);
1343 (void) fprintf(stderr
,
1344 "ifconfig: Bad prefix length in %s\n", addr
);
1350 lifr
.lifr_addr
= subnet
;
1351 lifr
.lifr_addrlen
= prefixlen
;
1352 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1353 if (ioctl(s
, SIOCSLIFSUBNET
, (caddr_t
)&lifr
) < 0)
1354 Perror0_exit("SIOCSLIFSUBNET");
1361 setifnetmask(char *addr
, int64_t param
)
1363 struct sockaddr_in netmask
;
1365 assert(afp
->af_af
!= AF_INET6
);
1367 if (strcmp(addr
, "+") == 0) {
1368 if (!in_getmask(&netmask
, _B_FALSE
))
1370 (void) printf("Setting netmask of %s to %s\n", name
,
1371 inet_ntoa(netmask
.sin_addr
));
1373 in_getaddr(addr
, (struct sockaddr
*)&netmask
, NULL
);
1375 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1376 (void) memcpy(&lifr
.lifr_addr
, &netmask
, sizeof (netmask
));
1377 if (ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
) < 0)
1378 Perror0_exit("SIOCSLIFNETMASK");
1383 * Parse '/<n>' as a netmask.
1387 setifprefixlen(char *addr
, int64_t param
)
1390 int af
= afp
->af_af
;
1392 prefixlen
= in_getprefixlen(addr
, _B_TRUE
,
1393 (af
== AF_INET
) ? IP_ABITS
: IPV6_ABITS
);
1394 if (prefixlen
< 0) {
1395 (void) fprintf(stderr
,
1396 "ifconfig: Bad prefix length in %s\n", addr
);
1399 (void) memset(&lifr
.lifr_addr
, 0, sizeof (lifr
.lifr_addr
));
1400 lifr
.lifr_addr
.ss_family
= af
;
1401 if (af
== AF_INET6
) {
1402 struct sockaddr_in6
*sin6
;
1404 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
1405 if (!in_prefixlentomask(prefixlen
, IPV6_ABITS
,
1406 (uchar_t
*)&sin6
->sin6_addr
)) {
1407 (void) fprintf(stderr
, "ifconfig: "
1408 "Bad prefix length: %d\n",
1412 } else if (af
== AF_INET
) {
1413 struct sockaddr_in
*sin
;
1415 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
1416 if (!in_prefixlentomask(prefixlen
, IP_ABITS
,
1417 (uchar_t
*)&sin
->sin_addr
)) {
1418 (void) fprintf(stderr
, "ifconfig: "
1419 "Bad prefix length: %d\n",
1424 (void) fprintf(stderr
, "ifconfig: setting prefix only supported"
1425 " for address family inet or inet6\n");
1428 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1429 if (ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
) < 0)
1430 Perror0_exit("SIOCSLIFNETMASK");
1436 setifbroadaddr(char *addr
, int64_t param
)
1438 struct sockaddr_in broadaddr
;
1440 assert(afp
->af_af
!= AF_INET6
);
1442 if (strcmp(addr
, "+") == 0) {
1444 * This doesn't set the broadcast address at all. Rather, it
1445 * gets, then sets the interface's address, relying on the fact
1446 * that resetting the address will reset the broadcast address.
1448 (void) strncpy(lifr
.lifr_name
, name
,
1449 sizeof (lifr
.lifr_name
));
1450 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
1451 if (errno
!= EADDRNOTAVAIL
)
1452 Perror0_exit("SIOCGLIFADDR");
1455 if (ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
) < 0)
1456 Perror0_exit("SIOCGLIFADDR");
1460 in_getaddr(addr
, (struct sockaddr
*)&broadaddr
, NULL
);
1462 (void) memcpy(&lifr
.lifr_addr
, &broadaddr
, sizeof (broadaddr
));
1463 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1464 if (ioctl(s
, SIOCSLIFBRDADDR
, (caddr_t
)&lifr
) < 0)
1465 Perror0_exit("SIOCSLIFBRDADDR");
1470 * set interface destination address
1474 setifdstaddr(char *addr
, int64_t param
)
1476 (*afp
->af_getaddr
)(addr
, (struct sockaddr
*)&lifr
.lifr_addr
, NULL
);
1477 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1478 if (ioctl(s
, SIOCSLIFDSTADDR
, (caddr_t
)&lifr
) < 0)
1479 Perror0_exit("setifdstaddr: SIOCSLIFDSTADDR");
1485 setifflags(char *val
, int64_t value
)
1487 struct lifreq lifrl
; /* local lifreq struct */
1488 boolean_t bringup
= _B_FALSE
;
1490 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1491 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0)
1492 Perror0_exit("setifflags: SIOCGLIFFLAGS");
1497 if ((value
& IFF_NOFAILOVER
) && (lifr
.lifr_flags
& IFF_UP
)) {
1499 * The kernel does not allow administratively up test
1500 * addresses to be converted to data addresses. Bring
1501 * the address down first, then bring it up after it's
1502 * been converted to a data address.
1504 lifr
.lifr_flags
&= ~IFF_UP
;
1505 (void) ioctl(s
, SIOCSLIFFLAGS
, (caddr_t
)&lifr
);
1509 lifr
.lifr_flags
&= ~value
;
1510 if ((value
& (IFF_UP
| IFF_NOFAILOVER
)) &&
1511 (lifr
.lifr_flags
& IFF_DUPLICATE
)) {
1513 * If the user is trying to mark an interface with a
1514 * duplicate address as "down," or convert a duplicate
1515 * test address to a data address, then fetch the
1516 * address and set it. This will cause IP to clear
1517 * the IFF_DUPLICATE flag and stop the automatic
1520 value
= lifr
.lifr_flags
;
1521 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) >= 0)
1522 (void) ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
);
1523 lifr
.lifr_flags
= value
;
1526 lifr
.lifr_flags
|= value
;
1530 * If we're about to bring up an underlying physical IPv6 interface in
1531 * an IPMP group, ensure the IPv6 IPMP interface is also up. This is
1532 * for backward compatibility with legacy configurations in which
1533 * there are no explicit hostname files for IPMP interfaces. (For
1534 * IPv4, this is automatically handled by the kernel when migrating
1535 * the underlying interface's data address to the IPMP interface.)
1537 (void) strlcpy(lifrl
.lifr_name
, name
, LIFNAMSIZ
);
1539 if (lifnum(lifr
.lifr_name
) == 0 &&
1540 (lifr
.lifr_flags
& (IFF_UP
|IFF_IPV6
)) == (IFF_UP
|IFF_IPV6
) &&
1541 ioctl(s
, SIOCGLIFGROUPNAME
, &lifrl
) == 0 &&
1542 lifrl
.lifr_groupname
[0] != '\0') {
1543 lifgroupinfo_t lifgr
;
1545 (void) strlcpy(lifgr
.gi_grname
, lifrl
.lifr_groupname
,
1547 if (ioctl(s
, SIOCGLIFGROUPINFO
, &lifgr
) == -1)
1548 Perror0_exit("setifflags: SIOCGLIFGROUPINFO");
1550 (void) strlcpy(lifrl
.lifr_name
, lifgr
.gi_grifname
, LIFNAMSIZ
);
1551 if (ioctl(s
, SIOCGLIFFLAGS
, &lifrl
) == -1)
1552 Perror0_exit("setifflags: SIOCGLIFFLAGS");
1553 if (!(lifrl
.lifr_flags
& IFF_UP
)) {
1554 lifrl
.lifr_flags
|= IFF_UP
;
1555 if (ioctl(s
, SIOCSLIFFLAGS
, &lifrl
) == -1)
1556 Perror0_exit("setifflags: SIOCSLIFFLAGS");
1560 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1561 if (ioctl(s
, SIOCSLIFFLAGS
, (caddr_t
)&lifr
) < 0)
1562 Perror0_exit("setifflags: SIOCSLIFFLAGS");
1565 lifr
.lifr_flags
|= IFF_UP
;
1566 if (ioctl(s
, SIOCSLIFFLAGS
, (caddr_t
)&lifr
) < 0)
1567 Perror0_exit("setifflags: SIOCSLIFFLAGS IFF_UP");
1575 setifmetric(char *val
, int64_t param
)
1577 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1578 lifr
.lifr_metric
= atoi(val
);
1579 if (ioctl(s
, SIOCSLIFMETRIC
, (caddr_t
)&lifr
) < 0)
1580 Perror0_exit("setifmetric: SIOCSLIFMETRIC");
1586 setifmtu(char *val
, int64_t param
)
1588 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1589 lifr
.lifr_mtu
= atoi(val
);
1590 if (ioctl(s
, SIOCSLIFMTU
, (caddr_t
)&lifr
) < 0)
1591 Perror0_exit("setifmtu: SIOCSLIFMTU");
1597 setifindex(char *val
, int64_t param
)
1599 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1600 lifr
.lifr_index
= atoi(val
);
1601 if (ioctl(s
, SIOCSLIFINDEX
, (caddr_t
)&lifr
) < 0)
1602 Perror0_exit("setifindex: SIOCSLIFINDEX");
1608 notifycb(dlpi_handle_t dh
, dlpi_notifyinfo_t
*dnip
, void *arg
)
1614 setifether(char *addr
, int64_t param
)
1619 ifaddrlistx_t
*ifaddrp
, *ifaddrs
= NULL
;
1625 print_ifether(name
);
1630 * if the IP interface in the arguments is a logical
1631 * interface, exit with an error now.
1633 if (strchr(name
, ':') != NULL
) {
1634 (void) fprintf(stderr
, "ifconfig: cannot change"
1635 " ethernet address of a logical interface\n");
1639 if ((hwaddr
= _link_aton(addr
, &hwaddrlen
)) == NULL
) {
1640 if (hwaddrlen
== -1)
1641 (void) fprintf(stderr
,
1642 "ifconfig: bad ethernet address\n");
1644 (void) fprintf(stderr
, "ifconfig: malloc() failed\n");
1648 if ((retval
= dlpi_open(name
, &dh
, 0)) != DLPI_SUCCESS
)
1649 Perrdlpi_exit("cannot dlpi_open() link", name
, retval
);
1651 retval
= dlpi_enabnotify(dh
, DL_NOTE_PHYS_ADDR
, notifycb
, NULL
, &id
);
1652 if (retval
== DLPI_SUCCESS
) {
1653 (void) dlpi_disabnotify(dh
, id
, NULL
);
1656 * This link does not support DL_NOTE_PHYS_ADDR: bring down
1657 * all of the addresses to flush the old hardware address
1658 * information out of IP.
1660 * NOTE: Skipping this when DL_NOTE_PHYS_ADDR is supported is
1661 * more than an optimization: in.mpathd will set IFF_OFFLINE
1662 * if it's notified and the new address is a duplicate of
1663 * another in the group -- but the flags manipulation in
1664 * ifaddr_{down,up}() cannot be atomic and thus might clobber
1665 * IFF_OFFLINE, confusing in.mpathd.
1667 if (ifaddrlistx(name
, IFF_UP
, 0, &ifaddrs
) == -1)
1668 Perror2_exit(name
, "cannot get address list");
1671 for (; ifaddrp
!= NULL
; ifaddrp
= ifaddrp
->ia_next
) {
1672 if (!ifaddr_down(ifaddrp
)) {
1673 Perror2_exit(ifaddrp
->ia_name
,
1674 "cannot bring down");
1680 * Change the hardware address.
1682 retval
= dlpi_set_physaddr(dh
, DL_CURR_PHYS_ADDR
, hwaddr
, hwaddrlen
);
1683 if (retval
!= DLPI_SUCCESS
) {
1684 (void) fprintf(stderr
,
1685 "ifconfig: failed setting mac address on %s\n", name
);
1690 * If any addresses were brought down before changing the hardware
1691 * address, bring them up again.
1693 for (ifaddrp
= ifaddrs
; ifaddrp
!= NULL
; ifaddrp
= ifaddrp
->ia_next
) {
1694 if (!ifaddr_up(ifaddrp
))
1695 Perror2_exit(ifaddrp
->ia_name
, "cannot bring up");
1697 ifaddrlistx_free(ifaddrs
);
1703 * Print an interface's Ethernet address, if it has one.
1706 print_ifether(const char *ifname
)
1710 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1712 fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
1713 if (fd
== -1 || ioctl(fd
, SIOCGLIFFLAGS
, &lifr
) == -1) {
1715 * It's possible the interface is only configured for
1716 * IPv6; check again with AF_INET6.
1719 fd
= socket(AF_INET6
, SOCK_DGRAM
, 0);
1720 if (fd
== -1 || ioctl(fd
, SIOCGLIFFLAGS
, &lifr
) == -1) {
1727 /* VNI and IPMP interfaces don't have MAC addresses */
1728 if (lifr
.lifr_flags
& (IFF_VIRTUAL
|IFF_IPMP
))
1731 /* IP tunnels also don't have Ethernet-like MAC addresses */
1732 if (ifconfig_dladm_open(ifname
, DATALINK_CLASS_IPTUN
, NULL
) ==
1736 dlpi_print_address(ifname
);
1740 * static int find_all_interfaces(struct lifconf *lifcp, char **buf,
1741 * int64_t lifc_flags)
1743 * It finds all active data links.
1745 * It takes in input a pointer to struct lifconf to receive interfaces
1746 * informations, a **char to hold allocated buffer, and a lifc_flags.
1753 find_all_interfaces(struct lifconf
*lifcp
, char **buf
, int64_t lifc_flags
)
1758 struct lifreq
*lifrp
;
1759 dladm_status_t status
;
1762 status
= ifconfig_dladm_open(NULL
, 0, NULL
);
1763 if (status
!= DLADM_STATUS_OK
)
1764 dladmerr_exit(status
, "unable to open dladm handle");
1767 (void) dlpi_walk(ni_entry
, dlh
, 0);
1769 /* Now, translate the linked list into a struct lifreq buffer */
1771 lifcp
->lifc_family
= AF_UNSPEC
;
1772 lifcp
->lifc_flags
= lifc_flags
;
1773 lifcp
->lifc_len
= 0;
1774 lifcp
->lifc_buf
= NULL
;
1778 bufsize
= num_ni
* sizeof (struct lifreq
);
1779 if ((*buf
= malloc(bufsize
)) == NULL
)
1780 Perror0_exit("find_all_interfaces: malloc failed");
1782 lifcp
->lifc_family
= AF_UNSPEC
;
1783 lifcp
->lifc_flags
= lifc_flags
;
1784 lifcp
->lifc_len
= bufsize
;
1785 lifcp
->lifc_buf
= *buf
;
1787 for (n
= 0, lifrp
= lifcp
->lifc_req
; n
< num_ni
; n
++, lifrp
++) {
1789 (void) strncpy(lifrp
->lifr_name
, nip
->ni_name
,
1790 sizeof (lifr
.lifr_name
));
1791 ni_list
= nip
->ni_next
;
1798 * Create the next unused logical interface using the original name
1799 * and assign the address (and mask if '/<n>' is part of the address).
1800 * Use the new logical interface for subsequent subcommands by updating
1801 * the name variable.
1803 * This allows syntax like:
1804 * ifconfig le0 addif 109.106.86.130 netmask + up \
1805 * addif 109.106.86.131 netmask + up
1809 addif(char *str
, int64_t param
)
1812 struct sockaddr_storage laddr
;
1813 struct sockaddr_storage mask
;
1814 struct sockaddr_in6
*sin6
;
1815 struct sockaddr_in
*sin
;
1816 ipadm_status_t istatus
;
1817 char cidraddr
[BUFSIZ
];
1818 char addrstr
[INET6_ADDRSTRLEN
];
1820 (void) strncpy(name
, origname
, sizeof (name
));
1822 if (strchr(name
, ':') != NULL
) {
1823 (void) fprintf(stderr
,
1824 "ifconfig: addif: bad physical interface name %s\n",
1830 * clear so parser will interpret next address as source followed
1834 (*afp
->af_getaddr
)(str
, (struct sockaddr
*)&laddr
, &prefixlen
);
1836 (void) memset(&mask
, 0, sizeof (mask
));
1837 mask
.ss_family
= afp
->af_af
;
1839 switch (prefixlen
) {
1841 /* Nothing there - ok */
1844 (void) fprintf(stderr
,
1845 "ifconfig: Bad prefix length in %s\n", str
);
1848 (void) memset(&mask
, 0, sizeof (mask
));
1849 mask
.ss_family
= afp
->af_af
;
1850 if (afp
->af_af
== AF_INET6
) {
1851 sin6
= (struct sockaddr_in6
*)&mask
;
1852 if (!in_prefixlentomask(prefixlen
, IPV6_ABITS
,
1853 (uchar_t
*)&sin6
->sin6_addr
)) {
1854 (void) fprintf(stderr
, "ifconfig: "
1855 "Bad prefix length: %d\n",
1860 sin
= (struct sockaddr_in
*)&mask
;
1861 if (!in_prefixlentomask(prefixlen
, IP_ABITS
,
1862 (uchar_t
*)&sin
->sin_addr
)) {
1863 (void) fprintf(stderr
, "ifconfig: "
1864 "Bad prefix length: %d\n",
1869 g_netmask_set
= G_NETMASK_NIL
;
1874 * This is a "hack" to get around the problem of SIOCLIFADDIF. The
1875 * problem is that this ioctl does not include the netmask when
1876 * adding a logical interface. This is the same problem described
1877 * in the ifconfig() comments. To get around this problem, we first
1878 * add the logical interface with a 0 address. After that, we set
1879 * the netmask if provided. Finally we set the interface address.
1881 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
1882 (void) memset(&lifr
.lifr_addr
, 0, sizeof (lifr
.lifr_addr
));
1884 /* Note: no need to do DAD here since the interface isn't up yet. */
1886 if (ioctl(s
, SIOCLIFADDIF
, (caddr_t
)&lifr
) < 0)
1887 Perror0_exit("addif: SIOCLIFADDIF");
1889 (void) printf("Created new logical interface %s\n",
1891 (void) strncpy(name
, lifr
.lifr_name
, sizeof (name
));
1894 * Check and see if any "netmask" command is used and perform the
1895 * necessary operation.
1897 set_mask_lifreq(&lifr
, &laddr
, &mask
);
1899 /* This check is temporary until libipadm supports IPMP interfaces. */
1900 if (ifconfig_use_libipadm(s
, name
)) {
1902 * We added the logical interface above before calling
1903 * ipadm_create_addr(), because, with IPH_LEGACY, we need
1904 * to do an addif for `ifconfig ce0 addif <addr>' but not for
1905 * `ifconfig ce0 <addr>'. libipadm does not have a flag to
1906 * to differentiate between these two cases. To keep it simple,
1907 * we always create the logical interface and pass it to
1908 * libipadm instead of requiring libipadm to addif for some
1909 * cases and not do addif for other cases.
1911 istatus
= ipadm_create_addrobj(IPADM_ADDR_STATIC
, name
,
1913 if (istatus
!= IPADM_SUCCESS
)
1914 ipadmerr_exit(istatus
, "addif");
1916 if (af
== AF_INET
) {
1917 sin
= (struct sockaddr_in
*)&laddr
;
1918 (void) inet_ntop(AF_INET
, &sin
->sin_addr
, addrstr
,
1921 sin6
= (struct sockaddr_in6
*)&laddr
;
1922 (void) inet_ntop(AF_INET6
, &sin6
->sin6_addr
, addrstr
,
1926 * lifr.lifr_addr, which is updated by set_mask_lifreq()
1927 * will contain the right mask to use.
1929 prefixlen
= mask2plen((struct sockaddr
*)&lifr
.lifr_addr
);
1931 (void) snprintf(cidraddr
, sizeof (cidraddr
), "%s/%d",
1932 addrstr
, prefixlen
);
1934 istatus
= ipadm_set_addr(ipaddr
, cidraddr
, af
);
1936 if (istatus
!= IPADM_SUCCESS
)
1937 ipadmerr_exit(istatus
, "could not set address");
1940 * address will be set by the parser after nextarg
1947 * Only set the netmask if "netmask" command is used or a prefix is
1950 if (g_netmask_set
== G_NETMASK_SET
|| prefixlen
>= 0) {
1952 * lifr.lifr_addr already contains netmask from
1953 * set_mask_lifreq().
1955 if (ioctl(s
, SIOCSLIFNETMASK
, (caddr_t
)&lifr
) < 0)
1956 Perror0_exit("addif: SIOCSLIFNETMASK");
1959 /* Finally, we set the interface address. */
1960 lifr
.lifr_addr
= laddr
;
1961 if (ioctl(s
, SIOCSLIFADDR
, (caddr_t
)&lifr
) < 0)
1962 Perror0_exit("SIOCSLIFADDR");
1965 * let parser know we got a source.
1966 * Next address, if given, should be dest
1973 * Remove a logical interface based on its IP address. Unlike addif
1974 * there is no '/<n>' here.
1975 * Verifies that the interface is down before it is removed.
1979 removeif(char *str
, int64_t param
)
1981 struct sockaddr_storage laddr
;
1982 ipadm_status_t istatus
;
1983 ipadm_addr_info_t
*ainfo
, *ainfop
;
1985 if (strchr(name
, ':') != NULL
) {
1986 (void) fprintf(stderr
,
1987 "ifconfig: removeif: bad physical interface name %s\n",
1992 (*afp
->af_getaddr
)(str
, &laddr
, NULL
);
1995 * Following check is temporary until libipadm supports
1998 if (!ifconfig_use_libipadm(s
, name
))
2002 * Get all addresses and search this address among the active
2003 * addresses. If an address object was found, delete using
2004 * ipadm_delete_addr().
2006 istatus
= ipadm_addr_info(iph
, name
, &ainfo
, 0, LIFC_DEFAULT
);
2007 if (istatus
!= IPADM_SUCCESS
)
2008 ipadmerr_exit(istatus
, "removeif");
2010 for (ainfop
= ainfo
; ainfop
!= NULL
; ainfop
= IA_NEXT(ainfop
))
2012 (struct sockaddr_storage
*)ainfop
->ia_ifa
.ifa_addr
, &laddr
))
2015 if (ainfop
!= NULL
) {
2016 if (strchr(ainfop
->ia_ifa
.ifa_name
, ':') == NULL
) {
2017 (void) fprintf(stderr
,
2018 "ifconfig: removeif: cannot remove interface: %s\n",
2022 if (ainfop
->ia_aobjname
[0] != '\0') {
2023 istatus
= ipadm_delete_addr(iph
, ainfop
->ia_aobjname
,
2025 if (istatus
!= IPADM_SUCCESS
) {
2026 ipadmerr_exit(istatus
,
2027 "could not delete address");
2029 ipadm_free_addr_info(ainfo
);
2033 ipadm_free_addr_info(ainfo
);
2037 * An address object for this address was not found in ipadm.
2038 * Delete with SIOCLIFREMOVEIF.
2040 lifr
.lifr_addr
= laddr
;
2041 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2042 if (ioctl(s
, SIOCLIFREMOVEIF
, (caddr_t
)&lifr
) < 0) {
2043 if (errno
== EBUSY
) {
2044 /* This can only happen if ipif_id = 0 */
2045 (void) fprintf(stderr
,
2046 "ifconfig: removeif: cannot remove interface: %s\n",
2050 Perror0_exit("removeif: SIOCLIFREMOVEIF");
2056 * Set the address token for IPv6.
2060 setiftoken(char *addr
, int64_t param
)
2063 struct sockaddr_in6 token
;
2065 in6_getaddr(addr
, (struct sockaddr
*)&token
, &prefixlen
);
2066 switch (prefixlen
) {
2068 (void) fprintf(stderr
,
2069 "ifconfig: Missing prefix length in subnet %s\n", addr
);
2073 (void) fprintf(stderr
,
2074 "ifconfig: Bad prefix length in %s\n", addr
);
2079 (void) memcpy(&lifr
.lifr_addr
, &token
, sizeof (token
));
2080 lifr
.lifr_addrlen
= prefixlen
;
2081 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2082 if (ioctl(s
, SIOCSLIFTOKEN
, (caddr_t
)&lifr
) < 0) {
2083 Perror0_exit("setiftoken: SIOCSLIFTOKEN");
2090 setifgroupname(char *grname
, int64_t param
)
2092 lifgroupinfo_t lifgr
;
2093 struct lifreq lifrl
;
2094 ifaddrlistx_t
*ifaddrp
, *nextifaddrp
;
2095 ifaddrlistx_t
*ifaddrs
= NULL
, *downaddrs
= NULL
;
2099 (void) printf("Setting groupname %s on interface %s\n",
2103 (void) strlcpy(lifrl
.lifr_name
, name
, LIFNAMSIZ
);
2104 (void) strlcpy(lifrl
.lifr_groupname
, grname
, LIFGRNAMSIZ
);
2106 while (ioctl(s
, SIOCSLIFGROUPNAME
, &lifrl
) == -1) {
2110 * The group doesn't yet exist; create it and repeat.
2113 if (create_ipmp(grname
, af
, NULL
, _B_TRUE
) == -1) {
2114 if (errno
== EEXIST
)
2117 Perror2(grname
, "cannot create IPMP group");
2124 * The interface is already in another group; must
2125 * remove existing membership first.
2127 lifrl
.lifr_groupname
[0] = '\0';
2128 if (ioctl(s
, SIOCSLIFGROUPNAME
, &lifrl
) == -1) {
2129 Perror2(name
, "cannot remove existing "
2130 "IPMP group membership");
2133 (void) strlcpy(lifrl
.lifr_groupname
, grname
,
2139 * The group exists, but it's not configured with the
2140 * address families the interface needs. Since only
2141 * two address families are currently supported, just
2142 * configure the "other" address family. Note that we
2143 * may race with group deletion or creation by another
2144 * process (ENOENT or EEXIST); in such cases we repeat
2145 * our original SIOCSLIFGROUPNAME.
2147 (void) strlcpy(lifgr
.gi_grname
, grname
, LIFGRNAMSIZ
);
2148 if (ioctl(s
, SIOCGLIFGROUPINFO
, &lifgr
) == -1) {
2149 if (errno
== ENOENT
)
2152 Perror2(grname
, "SIOCGLIFGROUPINFO");
2156 af
= lifgr
.gi_v4
? AF_INET6
: AF_INET
;
2157 if (create_ipmp(grname
, af
, lifgr
.gi_grifname
,
2159 if (errno
== EEXIST
)
2162 Perror2(grname
, "cannot configure IPMP group");
2169 * Some addresses are in-use (or under control of DAD).
2170 * Bring them down and retry the group join operation.
2171 * We will bring them back up after the interface has
2172 * been placed in the group.
2174 if (ifaddrlistx(lifrl
.lifr_name
, IFF_UP
|IFF_DUPLICATE
,
2175 0, &ifaddrs
) == -1) {
2176 Perror2(grname
, "cannot get address list");
2181 for (; ifaddrp
!= NULL
; ifaddrp
= nextifaddrp
) {
2182 if (!ifaddr_down(ifaddrp
)) {
2186 nextifaddrp
= ifaddrp
->ia_next
;
2187 ifaddrp
->ia_next
= downaddrs
;
2188 downaddrs
= ifaddrp
;
2193 case EADDRNOTAVAIL
: {
2195 * Some data addresses are under application control.
2196 * For some of these (e.g., ADDRCONF), the application
2197 * should remove the address, in which case we retry a
2198 * few times (since the application's action is not
2199 * atomic with respect to us) before bailing out and
2200 * informing the user.
2202 int ntries
, nappaddr
= 0;
2203 const if_appflags_t
*iap
= if_appflags_tbl
;
2205 for (; iap
->ia_app
!= NULL
; iap
++) {
2208 if (ifaddrlistx(lifrl
.lifr_name
, iap
->ia_flag
,
2209 IFF_NOFAILOVER
, &ifaddrs
) == -1) {
2210 (void) fprintf(stderr
, "ifconfig: %s: "
2211 "cannot get data addresses managed "
2212 "by %s\n", lifrl
.lifr_name
,
2217 if (ifaddrs
== NULL
)
2220 ifaddrlistx_free(ifaddrs
);
2223 if (++ntries
< iap
->ia_tries
) {
2224 (void) poll(NULL
, 0, 100);
2228 (void) fprintf(stderr
, "ifconfig: cannot join "
2229 "IPMP group: %s has data addresses managed "
2230 "by %s\n", lifrl
.lifr_name
, iap
->ia_app
);
2238 Perror2(name
, "SIOCSLIFGROUPNAME");
2244 * If the interface being moved is under the control of `ipmgmtd(1M)'
2245 * dameon then we should inform the daemon about this move, so that
2246 * the daemon can delete the state associated with this interface.
2248 * This workaround is needed until the IPMP support in ipadm(1M).
2250 ipadm_if_move(iph
, name
);
2253 * If there were addresses that we had to bring down, it's time to
2254 * bring them up again. As part of bringing them up, the kernel will
2255 * automatically move them to the new IPMP interface.
2257 for (ifaddrp
= downaddrs
; ifaddrp
!= NULL
; ifaddrp
= ifaddrp
->ia_next
) {
2258 if (!ifaddr_up(ifaddrp
) && errno
!= ENXIO
) {
2259 (void) fprintf(stderr
, "ifconfig: cannot bring back up "
2260 "%s: %s\n", ifaddrp
->ia_name
, strerror(errno
));
2263 ifaddrlistx_free(downaddrs
);
2267 * Attempt to bring back up any interfaces that we downed.
2269 for (ifaddrp
= downaddrs
; ifaddrp
!= NULL
; ifaddrp
= ifaddrp
->ia_next
) {
2270 if (!ifaddr_up(ifaddrp
) && errno
!= ENXIO
) {
2271 (void) fprintf(stderr
, "ifconfig: cannot bring back up "
2272 "%s: %s\n", ifaddrp
->ia_name
, strerror(errno
));
2275 ifaddrlistx_free(downaddrs
);
2276 ifaddrlistx_free(ifaddrs
);
2279 * We'd return -1, but foreachinterface() doesn't propagate the error
2280 * into the exit status, so we're forced to explicitly exit().
2287 modcheck(const char *ifname
)
2289 (void) strlcpy(lifr
.lifr_name
, ifname
, sizeof (lifr
.lifr_name
));
2291 if (ioctl(s
, SIOCGLIFFLAGS
, &lifr
) < 0) {
2292 Perror0("SIOCGLIFFLAGS");
2296 if (lifr
.lifr_flags
& IFF_IPMP
) {
2297 (void) fprintf(stderr
, "ifconfig: %s: module operations not"
2298 " supported on IPMP interfaces\n", ifname
);
2301 if (lifr
.lifr_flags
& IFF_VIRTUAL
) {
2302 (void) fprintf(stderr
, "ifconfig: %s: module operations not"
2303 " supported on virtual IP interfaces\n", ifname
);
2310 * To list all the modules above a given network interface.
2314 modlist(char *null
, int64_t param
)
2322 struct str_list strlist
;
2326 * We'd return -1, but foreachinterface() doesn't propagate the error
2327 * into the exit status, so we're forced to explicitly exit().
2329 if (!modcheck(name
))
2332 if (ip_domux2fd(&muxfd
, &muxid_fd
, &ipfd_lowstr
, &arpfd_lowstr
,
2336 if ((num_mods
= ioctl(ipfd_lowstr
, I_LIST
, NULL
)) < 0) {
2337 Perror0("cannot I_LIST to get the number of modules");
2340 (void) printf("Listing (%d) modules above %s\n",
2344 strlist
.sl_nmods
= num_mods
;
2345 strlist
.sl_modlist
= malloc(sizeof (struct str_mlist
) *
2347 if (strlist
.sl_modlist
== NULL
) {
2348 Perror0("cannot malloc");
2350 if (ioctl(ipfd_lowstr
, I_LIST
, (caddr_t
)&strlist
) < 0) {
2351 Perror0("cannot I_LIST for module names");
2353 for (i
= 0; i
< strlist
.sl_nmods
; i
++) {
2354 (void) printf("%d %s\n", i
,
2355 strlist
.sl_modlist
[i
].l_name
);
2358 free(strlist
.sl_modlist
);
2361 return (ip_plink(muxfd
, muxid_fd
, ipfd_lowstr
, arpfd_lowstr
,
2365 #define MODINSERT_OP 'i'
2366 #define MODREMOVE_OP 'r'
2369 * To insert a module to the stream of the interface. It is just a
2370 * wrapper. The real function is modop().
2374 modinsert(char *arg
, int64_t param
)
2376 return (modop(arg
, MODINSERT_OP
));
2380 * To remove a module from the stream of the interface. It is just a
2381 * wrapper. The real function is modop().
2385 modremove(char *arg
, int64_t param
)
2387 return (modop(arg
, MODREMOVE_OP
));
2391 * Helper function for mod*() functions. It gets a fd to the lower IP
2392 * stream and I_PUNLINK's the lower stream. It also initializes the
2393 * global variable lifr.
2396 * int *muxfd: fd to /dev/udp{,6} for I_PLINK/I_PUNLINK
2397 * int *muxid_fd: fd to /dev/udp{,6} for LIFMUXID
2398 * int *ipfd_lowstr: fd to the lower IP stream.
2399 * int *arpfd_lowstr: fd to the lower ARP stream.
2402 * -1 if operation fails, 0 otherwise.
2404 * Please see the big block comment above ifplumb() for the logic of the
2408 ip_domux2fd(int *muxfd
, int *muxid_fd
, int *ipfd_lowstr
, int *arpfd_lowstr
,
2415 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2416 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0) {
2417 Perror0_exit("status: SIOCGLIFFLAGS");
2419 flags
= lifr
.lifr_flags
;
2420 if (flags
& IFF_IPV4
) {
2421 udp_dev_name
= UDP_DEV_NAME
;
2422 } else if (flags
& IFF_IPV6
) {
2423 udp_dev_name
= UDP6_DEV_NAME
;
2428 if ((*muxid_fd
= open(udp_dev_name
, O_RDWR
)) < 0) {
2429 Perror2("open", udp_dev_name
);
2432 if (ioctl(*muxid_fd
, SIOCGLIFMUXID
, (caddr_t
)&lifr
) < 0) {
2433 Perror2("SIOCGLIFMUXID", udp_dev_name
);
2437 (void) printf("ARP_muxid %d IP_muxid %d\n",
2438 lifr
.lifr_arp_muxid
, lifr
.lifr_ip_muxid
);
2442 * Use /dev/udp{,6} as the mux to avoid linkcycles.
2444 if (ipadm_open_arp_on_udp(udp_dev_name
, muxfd
) != IPADM_SUCCESS
)
2447 if (lifr
.lifr_arp_muxid
!= 0) {
2448 if ((*arpfd_lowstr
= ioctl(*muxfd
, _I_MUXID2FD
,
2449 lifr
.lifr_arp_muxid
)) < 0) {
2450 if ((errno
== EINVAL
) &&
2451 (flags
& (IFF_NOARP
| IFF_IPV6
))) {
2453 * Some plumbing utilities set the muxid to
2454 * -1 or some invalid value to signify that
2455 * there is no arp stream. Set the muxid to 0
2456 * before trying to unplumb the IP stream.
2457 * IP does not allow the IP stream to be
2458 * unplumbed if it sees a non-null arp muxid,
2459 * for consistency of IP-ARP streams.
2461 *orig_arpid
= lifr
.lifr_arp_muxid
;
2462 lifr
.lifr_arp_muxid
= 0;
2463 (void) ioctl(*muxid_fd
, SIOCSLIFMUXID
,
2467 Perror0("_I_MUXID2FD");
2470 } else if (ioctl(*muxfd
, I_PUNLINK
,
2471 lifr
.lifr_arp_muxid
) < 0) {
2472 Perror2("I_PUNLINK", udp_dev_name
);
2479 if ((*ipfd_lowstr
= ioctl(*muxfd
, _I_MUXID2FD
,
2480 lifr
.lifr_ip_muxid
)) < 0) {
2481 Perror0("_I_MUXID2FD");
2482 /* Undo any changes we made */
2483 if (*orig_arpid
!= 0) {
2484 lifr
.lifr_arp_muxid
= *orig_arpid
;
2485 (void) ioctl(*muxid_fd
, SIOCSLIFMUXID
, (caddr_t
)&lifr
);
2489 if (ioctl(*muxfd
, I_PUNLINK
, lifr
.lifr_ip_muxid
) < 0) {
2490 Perror2("I_PUNLINK", udp_dev_name
);
2491 /* Undo any changes we made */
2492 if (*orig_arpid
!= 0) {
2493 lifr
.lifr_arp_muxid
= *orig_arpid
;
2494 (void) ioctl(*muxid_fd
, SIOCSLIFMUXID
, (caddr_t
)&lifr
);
2502 * Helper function for mod*() functions. It I_PLINK's back the upper and
2503 * lower IP streams. Note that this function must be called after
2504 * ip_domux2fd(). In ip_domux2fd(), the global variable lifr is initialized
2505 * and ip_plink() needs information in lifr. So ip_domux2fd() and ip_plink()
2506 * must be called in pairs.
2509 * int muxfd: fd to /dev/udp{,6} for I_PLINK/I_PUNLINK
2510 * int muxid_fd: fd to /dev/udp{,6} for LIFMUXID
2511 * int ipfd_lowstr: fd to the lower IP stream.
2512 * int arpfd_lowstr: fd to the lower ARP stream.
2515 * -1 if operation fails, 0 otherwise.
2517 * Please see the big block comment above ifplumb() for the logic of the
2521 ip_plink(int muxfd
, int muxid_fd
, int ipfd_lowstr
, int arpfd_lowstr
,
2526 ip_muxid
= ioctl(muxfd
, I_PLINK
, ipfd_lowstr
);
2528 Perror2("I_PLINK", UDP_DEV_NAME
);
2533 * If there is an arp stream, plink it. If there is no
2534 * arp stream, then it is possible that the plumbing
2535 * utility could have stored any value in the arp_muxid.
2536 * If so, restore it from orig_arpid.
2538 if (arpfd_lowstr
!= -1) {
2539 if (ioctl(muxfd
, I_PLINK
, arpfd_lowstr
) < 0) {
2540 Perror2("I_PLINK", UDP_DEV_NAME
);
2543 } else if (orig_arpid
!= 0) {
2544 /* Undo the changes we did in ip_domux2fd */
2545 lifr
.lifr_arp_muxid
= orig_arpid
;
2546 lifr
.lifr_ip_muxid
= ip_muxid
;
2547 (void) ioctl(muxid_fd
, SIOCSLIFMUXID
, (caddr_t
)&lifr
);
2550 (void) close(muxfd
);
2551 (void) close(muxid_fd
);
2556 * The real function to perform module insertion/removal.
2559 * char *arg: the argument string module_name@position
2560 * char op: operation, either MODINSERT_OP or MODREMOVE_OP.
2563 * Before doing ip_domux2fd(), this function calls exit(1) in case of
2564 * error. After ip_domux2fd() is done, it returns -1 for error, 0
2568 modop(char *arg
, char op
)
2573 int ipfd_lowstr
; /* IP stream (lower stream of mux) to be plinked */
2574 int arpfd_lowstr
; /* ARP stream (lower stream of mux) to be plinked */
2575 struct strmodconf mod
;
2576 char *at_char
= "@";
2581 * We'd return -1, but foreachinterface() doesn't propagate the error
2582 * into the exit status, so we're forced to explicitly exit().
2584 if (!modcheck(name
))
2587 /* Need to save the original string for -a option. */
2588 if ((arg_str
= malloc(strlen(arg
) + 1)) == NULL
) {
2589 Perror0("cannot malloc");
2592 (void) strcpy(arg_str
, arg
);
2594 if (*arg_str
== *at_char
) {
2595 (void) fprintf(stderr
,
2596 "ifconfig: must supply a module name\n");
2599 mod
.mod_name
= strtok(arg_str
, at_char
);
2600 if (strlen(mod
.mod_name
) > FMNAMESZ
) {
2601 (void) fprintf(stderr
, "ifconfig: module name too long: %s\n",
2607 * Need to make sure that the core TCP/IP stack modules are not
2608 * removed. Otherwise, "bad" things can happen. If a module
2609 * is removed and inserted back, it loses its old state. But
2610 * the modules above it still have the old state. E.g. IP assumes
2611 * fast data path while tunnel after re-inserted assumes that it can
2612 * receive M_DATA only in fast data path for which it does not have
2613 * any state. This is a general caveat of _I_REMOVE/_I_INSERT.
2615 if (op
== MODREMOVE_OP
&&
2616 (strcmp(mod
.mod_name
, ARP_MOD_NAME
) == 0 ||
2617 strcmp(mod
.mod_name
, IP_MOD_NAME
) == 0)) {
2618 (void) fprintf(stderr
, "ifconfig: cannot remove %s\n",
2623 if ((pos_p
= strtok(NULL
, at_char
)) == NULL
) {
2624 (void) fprintf(stderr
, "ifconfig: must supply a position\n");
2627 mod
.pos
= atoi(pos_p
);
2629 if (ip_domux2fd(&muxfd
, &muxid_fd
, &ipfd_lowstr
, &arpfd_lowstr
,
2637 (void) printf("Inserting module %s at %d\n",
2638 mod
.mod_name
, mod
.pos
);
2640 if (ioctl(ipfd_lowstr
, _I_INSERT
, (caddr_t
)&mod
) < 0) {
2641 Perror2("fail to insert module", mod
.mod_name
);
2646 (void) printf("Removing module %s at %d\n",
2647 mod
.mod_name
, mod
.pos
);
2649 if (ioctl(ipfd_lowstr
, _I_REMOVE
, (caddr_t
)&mod
) < 0) {
2650 Perror2("fail to remove module", mod
.mod_name
);
2654 /* Should never get to here. */
2655 (void) fprintf(stderr
, "Unknown operation\n");
2659 return (ip_plink(muxfd
, muxid_fd
, ipfd_lowstr
, arpfd_lowstr
,
2664 modify_tun(iptun_params_t
*params
)
2666 dladm_status_t status
;
2668 if ((status
= ifconfig_dladm_open(name
, DATALINK_CLASS_IPTUN
,
2669 ¶ms
->iptun_param_linkid
)) == DLADM_STATUS_OK
)
2670 status
= dladm_iptun_modify(dlh
, params
, DLADM_OPT_ACTIVE
);
2671 if (status
!= DLADM_STATUS_OK
)
2672 dladmerr_exit(status
, name
);
2677 * Set tunnel source address
2681 setiftsrc(char *addr
, int64_t param
)
2683 iptun_params_t params
;
2685 params
.iptun_param_flags
= IPTUN_PARAM_LADDR
;
2686 (void) strlcpy(params
.iptun_param_laddr
, addr
,
2687 sizeof (params
.iptun_param_laddr
));
2688 return (modify_tun(¶ms
));
2692 * Set tunnel destination address
2696 setiftdst(char *addr
, int64_t param
)
2698 iptun_params_t params
;
2700 params
.iptun_param_flags
= IPTUN_PARAM_RADDR
;
2701 (void) strlcpy(params
.iptun_param_raddr
, addr
,
2702 sizeof (params
.iptun_param_raddr
));
2703 return (modify_tun(¶ms
));
2707 set_tun_prop(const char *propname
, char *value
)
2709 dladm_status_t status
;
2710 datalink_id_t linkid
;
2712 status
= ifconfig_dladm_open(name
, DATALINK_CLASS_IPTUN
, &linkid
);
2713 if (status
== DLADM_STATUS_OK
) {
2714 status
= dladm_set_linkprop(dlh
, linkid
, propname
, &value
, 1,
2717 if (status
!= DLADM_STATUS_OK
)
2718 dladmerr_exit(status
, name
);
2722 /* Set tunnel encapsulation limit. */
2725 set_tun_encap_limit(char *arg
, int64_t param
)
2727 return (set_tun_prop("encaplimit", arg
));
2730 /* Disable encapsulation limit. */
2733 clr_tun_encap_limit(char *arg
, int64_t param
)
2735 return (set_tun_encap_limit("-1", 0));
2738 /* Set tunnel hop limit. */
2741 set_tun_hop_limit(char *arg
, int64_t param
)
2743 return (set_tun_prop("hoplimit", arg
));
2748 setzone(char *arg
, int64_t param
)
2750 zoneid_t zoneid
= GLOBAL_ZONEID
;
2752 if (param
== NEXTARG
) {
2753 /* zone must be active */
2754 if ((zoneid
= getzoneidbyname(arg
)) == -1) {
2755 (void) fprintf(stderr
,
2756 "ifconfig: unknown zone '%s'\n", arg
);
2760 (void) strlcpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2761 lifr
.lifr_zoneid
= zoneid
;
2762 if (ioctl(s
, SIOCSLIFZONE
, (caddr_t
)&lifr
) == -1)
2763 Perror0_exit("SIOCSLIFZONE");
2767 /* Set source address to use */
2770 setifsrc(char *arg
, int64_t param
)
2775 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2778 * Argument can be either an interface name or "none". The latter means
2779 * that any previous selection is cleared.
2782 if (strchr(arg
, ':') != NULL
) {
2783 (void) fprintf(stderr
,
2784 "ifconfig: Cannot specify logical interface for usesrc \n");
2788 rval
= strcmp(arg
, NONE_STR
);
2790 if ((ifindex
= if_nametoindex(arg
)) == 0) {
2791 (void) strncpy(lifr
.lifr_name
, arg
, LIFNAMSIZ
);
2792 Perror0_exit("Could not get interface index");
2794 lifr
.lifr_index
= ifindex
;
2796 if (ioctl(s
, SIOCGLIFUSESRC
, (caddr_t
)&lifr
) != 0)
2797 Perror0_exit("Not a valid usesrc consumer");
2798 lifr
.lifr_index
= 0;
2802 (void) printf("setifsrc: lifr_name %s, lifr_index %d\n",
2803 lifr
.lifr_name
, lifr
.lifr_index
);
2805 if (ioctl(s
, SIOCSLIFUSESRC
, (caddr_t
)&lifr
) == -1) {
2807 Perror0_exit("Cannot reset usesrc group");
2809 Perror0_exit("Could not set source interface");
2816 * Print the interface status line associated with `ifname'
2819 ifstatus(const char *ifname
)
2822 char if_usesrc_name
[LIFNAMSIZ
];
2824 int n
, numifs
, rval
= 0;
2825 struct lifreq
*lifrp
;
2826 struct lifsrcof lifs
;
2828 (void) strncpy(lifr
.lifr_name
, ifname
, sizeof (lifr
.lifr_name
));
2829 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0) {
2830 Perror0_exit("status: SIOCGLIFFLAGS");
2832 flags
= lifr
.lifr_flags
;
2835 * In V4 compatibility mode, we don't print the IFF_IPV4 flag or
2836 * interfaces with IFF_IPV6 set.
2840 if (flags
& IFF_IPV6
)
2844 (void) printf("%s: ", ifname
);
2847 (void) strncpy(lifr
.lifr_name
, ifname
, sizeof (lifr
.lifr_name
));
2848 if (ioctl(s
, SIOCGLIFMETRIC
, (caddr_t
)&lifr
) < 0) {
2849 Perror0_exit("status: SIOCGLIFMETRIC");
2851 if (lifr
.lifr_metric
)
2852 (void) printf(" metric %d", lifr
.lifr_metric
);
2854 if (ioctl(s
, SIOCGLIFMTU
, (caddr_t
)&lifr
) >= 0)
2855 (void) printf(" mtu %u", lifr
.lifr_mtu
);
2857 /* don't print index or zone when in compatibility mode */
2859 if (ioctl(s
, SIOCGLIFINDEX
, (caddr_t
)&lifr
) >= 0)
2860 (void) printf(" index %d", lifr
.lifr_index
);
2862 * Stack instances use GLOBAL_ZONEID for IP data structures
2863 * even in the non-global zone.
2865 if (ioctl(s
, SIOCGLIFZONE
, (caddr_t
)&lifr
) >= 0 &&
2866 lifr
.lifr_zoneid
!= getzoneid() &&
2867 lifr
.lifr_zoneid
!= GLOBAL_ZONEID
) {
2868 char zone_name
[ZONENAME_MAX
];
2870 if (getzonenamebyid(lifr
.lifr_zoneid
, zone_name
,
2871 sizeof (zone_name
)) < 0) {
2872 (void) printf("\n\tzone %d", lifr
.lifr_zoneid
);
2874 (void) printf("\n\tzone %s", zone_name
);
2879 if (ioctl(s
, SIOCGLIFINDEX
, (caddr_t
)&lifr
) >= 0) {
2880 lifs
.lifs_ifindex
= lifr
.lifr_index
;
2883 * Find the number of interfaces that use this interfaces'
2884 * address as a source address
2886 lifs
.lifs_buf
= NULL
;
2887 lifs
.lifs_maxlen
= 0;
2889 /* The first pass will give the bufsize we need */
2890 rval
= ioctl(s
, SIOCGLIFSRCOF
, (char *)&lifs
);
2892 if (lifs
.lifs_buf
!= NULL
) {
2893 free(lifs
.lifs_buf
);
2894 lifs
.lifs_buf
= NULL
;
2899 if (lifs
.lifs_len
<= lifs
.lifs_maxlen
)
2901 /* Use kernel's size + a small margin to avoid loops */
2902 lifs
.lifs_maxlen
= lifs
.lifs_len
+
2903 5 * sizeof (struct lifreq
);
2904 /* For the first pass, realloc acts like malloc */
2905 newbuf
= realloc(lifs
.lifs_buf
, lifs
.lifs_maxlen
);
2906 if (newbuf
== NULL
) {
2907 if (lifs
.lifs_buf
!= NULL
) {
2908 free(lifs
.lifs_buf
);
2909 lifs
.lifs_buf
= NULL
;
2914 lifs
.lifs_buf
= newbuf
;
2918 numifs
= lifs
.lifs_len
/ sizeof (struct lifreq
);
2920 lifrp
= lifs
.lifs_req
;
2921 (void) printf("\n\tsrcof");
2922 for (n
= numifs
; n
> 0; n
--, lifrp
++) {
2923 (void) printf(" %s", lifrp
->lifr_name
);
2927 free(lifs
.lifs_buf
);
2930 /* Find the interface whose source address this interface uses */
2931 if (ioctl(s
, SIOCGLIFUSESRC
, (caddr_t
)&lifr
) == 0) {
2932 if (lifr
.lifr_index
!= 0) {
2933 if (if_indextoname(lifr
.lifr_index
,
2934 if_usesrc_name
) == NULL
) {
2935 (void) printf("\n\tusesrc ifIndex %d",
2938 (void) printf("\n\tusesrc %s", if_usesrc_name
);
2943 (void) putchar('\n');
2947 * Print the status of the interface. If an address family was
2948 * specified, show it and it only; otherwise, show them all.
2953 struct afswtch
*p
= afp
;
2955 datalink_id_t linkid
;
2957 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
2958 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0) {
2959 Perror0_exit("status: SIOCGLIFFLAGS");
2962 flags
= lifr
.lifr_flags
;
2965 * Only print the interface status if the address family matches
2966 * the interface family flag.
2969 if (((p
->af_af
== AF_INET6
) && (flags
& IFF_IPV4
)) ||
2970 ((p
->af_af
== AF_INET
) && (flags
& IFF_IPV6
)))
2975 * In V4 compatibility mode, don't print IFF_IPV6 interfaces.
2977 if (v4compat
&& (flags
& IFF_IPV6
))
2982 if (ifconfig_dladm_open(name
, DATALINK_CLASS_IPTUN
, &linkid
) ==
2987 (*p
->af_status
)(1, flags
);
2989 for (p
= afs
; p
->af_name
; p
++) {
2990 /* set global af for use in p->af_status */
2992 (*p
->af_status
)(0, flags
);
2996 * Historically, 'ether' has been an address family,
2999 print_ifether(name
);
3004 * Print the status of the interface in a format that can be used to
3005 * reconfigure the interface later. Code stolen from status() above.
3009 configinfo(char *null
, int64_t param
)
3012 struct afswtch
*p
= afp
;
3014 char lifname
[LIFNAMSIZ
];
3015 char if_usesrc_name
[LIFNAMSIZ
];
3017 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3019 if (ioctl(s
, SIOCGLIFFLAGS
, (caddr_t
)&lifr
) < 0) {
3020 Perror0_exit("status: SIOCGLIFFLAGS");
3022 flags
= lifr
.lifr_flags
;
3025 (void) printf("configinfo: name %s flags 0x%llx af_af %d\n",
3026 name
, flags
, p
!= NULL
? p
->af_af
: -1);
3030 * Build the interface name to print (we cannot directly use `name'
3031 * because one cannot "plumb" ":0" interfaces).
3033 (void) strlcpy(lifname
, name
, LIFNAMSIZ
);
3034 if ((cp
= strchr(lifname
, ':')) != NULL
&& atoi(cp
+ 1) == 0)
3038 * if the interface is IPv4
3039 * if we have a IPv6 address family restriction return
3041 * if we are in IPv4 compatibility mode, clear out IFF_IPV4
3042 * so we don't print it.
3044 if (flags
& IFF_IPV4
) {
3045 if (p
&& p
->af_af
== AF_INET6
)
3050 (void) printf("%s inet plumb", lifname
);
3051 } else if (flags
& IFF_IPV6
) {
3053 * else if the interface is IPv6
3054 * if we have a IPv4 address family restriction return
3055 * or we are in IPv4 compatibiltiy mode, return.
3057 if (p
&& p
->af_af
== AF_INET
)
3062 (void) printf("%s inet6 plumb", lifname
);
3065 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3066 if (ioctl(s
, SIOCGLIFMETRIC
, (caddr_t
)&lifr
) < 0) {
3067 Perror0_exit("configinfo: SIOCGLIFMETRIC");
3069 if (lifr
.lifr_metric
)
3070 (void) printf(" metric %d ", lifr
.lifr_metric
);
3072 if (((flags
& (IFF_VIRTUAL
|IFF_LOOPBACK
)) != IFF_VIRTUAL
) &&
3073 ioctl(s
, SIOCGLIFMTU
, (caddr_t
)&lifr
) >= 0)
3074 (void) printf(" mtu %u", lifr
.lifr_mtu
);
3076 /* Index only applies to the zeroth interface */
3077 if (lifnum(name
) == 0) {
3078 if (ioctl(s
, SIOCGLIFINDEX
, (caddr_t
)&lifr
) >= 0)
3079 (void) printf(" index %d", lifr
.lifr_index
);
3082 if (ioctl(s
, SIOCGLIFUSESRC
, (caddr_t
)&lifr
) == 0) {
3083 if (lifr
.lifr_index
!= 0) {
3084 if (if_indextoname(lifr
.lifr_index
,
3085 if_usesrc_name
) != NULL
) {
3086 (void) printf(" usesrc %s", if_usesrc_name
);
3092 (*p
->af_configinfo
)(1, flags
);
3094 for (p
= afs
; p
->af_name
; p
++) {
3096 s
= socket(SOCKET_AF(p
->af_af
), SOCK_DGRAM
, 0);
3097 /* set global af for use in p->af_configinfo */
3100 Perror0_exit("socket");
3102 (*p
->af_configinfo
)(0, flags
);
3106 (void) putchar('\n');
3111 print_tsec(iptun_params_t
*params
)
3115 (void) printf("\ttunnel security settings ");
3116 if (!(params
->iptun_param_flags
& IPTUN_PARAM_SECINFO
)) {
3117 (void) printf("--> use 'ipsecconf -ln -i %s'", name
);
3119 ipsr
= ¶ms
->iptun_param_secinfo
;
3120 if (ipsr
->ipsr_ah_req
& IPSEC_PREF_REQUIRED
) {
3121 (void) printf("ah (%s) ",
3122 rparsealg(ipsr
->ipsr_auth_alg
, IPSEC_PROTO_AH
));
3124 if (ipsr
->ipsr_esp_req
& IPSEC_PREF_REQUIRED
) {
3125 (void) printf("esp (%s",
3126 rparsealg(ipsr
->ipsr_esp_alg
, IPSEC_PROTO_ESP
));
3127 (void) printf("/%s)",
3128 rparsealg(ipsr
->ipsr_esp_auth_alg
, IPSEC_PROTO_AH
));
3131 (void) printf("\n");
3135 tun_status(datalink_id_t linkid
)
3137 iptun_params_t params
;
3138 char propval
[DLADM_PROP_VAL_MAX
];
3141 boolean_t tabbed
= _B_FALSE
;
3143 params
.iptun_param_linkid
= linkid
;
3145 /* If dladm_iptun_getparams() fails, assume we are not a tunnel. */
3147 if (dladm_iptun_getparams(dlh
, ¶ms
, DLADM_OPT_ACTIVE
) !=
3151 switch (params
.iptun_param_type
) {
3152 case IPTUN_TYPE_IPV4
:
3153 case IPTUN_TYPE_6TO4
:
3154 (void) printf("\tinet");
3156 case IPTUN_TYPE_IPV6
:
3157 (void) printf("\tinet6");
3160 dladmerr_exit(DLADM_STATUS_IPTUNTYPE
, name
);
3165 * There is always a source address. If it hasn't been explicitly
3166 * set, the API will pass back a buffer containing the unspecified
3169 (void) printf(" tunnel src %s ", params
.iptun_param_laddr
);
3171 if (params
.iptun_param_flags
& IPTUN_PARAM_RADDR
)
3172 (void) printf("tunnel dst %s\n", params
.iptun_param_raddr
);
3174 (void) putchar('\n');
3176 if (params
.iptun_param_flags
& IPTUN_PARAM_IPSECPOL
)
3177 print_tsec(¶ms
);
3179 valptr
[0] = propval
;
3180 if (dladm_get_linkprop(dlh
, linkid
, DLADM_PROP_VAL_CURRENT
, "hoplimit",
3181 (char **)valptr
, &valcnt
) == DLADM_STATUS_OK
) {
3182 (void) printf("\ttunnel hop limit %s ", propval
);
3186 if (dladm_get_linkprop(dlh
, linkid
, DLADM_PROP_VAL_CURRENT
,
3187 "encaplimit", (char **)valptr
, &valcnt
) == DLADM_STATUS_OK
) {
3191 (void) putchar('\t');
3194 elim
= strtol(propval
, NULL
, 10);
3196 (void) printf("tunnel encapsulation limit %s", propval
);
3198 (void) printf("tunnel encapsulation limit disabled");
3202 (void) putchar('\n');
3206 in_status(int force
, uint64_t flags
)
3208 struct sockaddr_in
*sin
, *laddr
;
3209 struct sockaddr_in netmask
= { AF_INET
};
3212 (void) printf("in_status(%s) flags 0x%llx\n", name
, flags
);
3214 /* only print status for IPv4 interfaces */
3215 if (!(flags
& IFF_IPV4
))
3218 if (!(flags
& IFF_NOLOCAL
)) {
3219 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3220 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
3221 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3225 (void) memset(&lifr
.lifr_addr
, 0,
3226 sizeof (lifr
.lifr_addr
));
3228 Perror0_exit("in_status: SIOCGLIFADDR");
3230 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3231 (void) printf("\tinet %s ", inet_ntoa(sin
->sin_addr
));
3234 (void) printf("\tinet ");
3237 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3238 if (ioctl(s
, SIOCGLIFSUBNET
, (caddr_t
)&lifr
) < 0) {
3239 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3243 (void) memset(&lifr
.lifr_addr
, 0,
3244 sizeof (lifr
.lifr_addr
));
3246 Perror0_exit("in_status: SIOCGLIFSUBNET");
3249 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3250 if ((flags
& IFF_NOLOCAL
) ||
3251 sin
->sin_addr
.s_addr
!= laddr
->sin_addr
.s_addr
) {
3252 (void) printf("subnet %s/%d ", inet_ntoa(sin
->sin_addr
),
3255 if (sin
->sin_family
!= AF_INET
) {
3256 (void) printf("Wrong family: %d\n", sin
->sin_family
);
3259 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3260 if (ioctl(s
, SIOCGLIFNETMASK
, (caddr_t
)&lifr
) < 0) {
3261 if (errno
!= EADDRNOTAVAIL
)
3262 Perror0_exit("in_status: SIOCGLIFNETMASK");
3263 (void) memset(&lifr
.lifr_addr
, 0, sizeof (lifr
.lifr_addr
));
3266 ((struct sockaddr_in
*)&lifr
.lifr_addr
)->sin_addr
;
3267 if (flags
& IFF_POINTOPOINT
) {
3268 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3269 if (ioctl(s
, SIOCGLIFDSTADDR
, (caddr_t
)&lifr
) < 0) {
3270 if (errno
== EADDRNOTAVAIL
)
3271 (void) memset(&lifr
.lifr_addr
, 0,
3272 sizeof (lifr
.lifr_addr
));
3274 Perror0_exit("in_status: SIOCGLIFDSTADDR");
3276 sin
= (struct sockaddr_in
*)&lifr
.lifr_dstaddr
;
3277 (void) printf("--> %s ", inet_ntoa(sin
->sin_addr
));
3279 (void) printf("netmask %x ", ntohl(netmask
.sin_addr
.s_addr
));
3280 if (flags
& IFF_BROADCAST
) {
3281 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3282 if (ioctl(s
, SIOCGLIFBRDADDR
, (caddr_t
)&lifr
) < 0) {
3283 if (errno
== EADDRNOTAVAIL
)
3284 (void) memset(&lifr
.lifr_addr
, 0,
3285 sizeof (lifr
.lifr_addr
));
3287 Perror0_exit("in_status: SIOCGLIFBRDADDR");
3289 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3290 if (sin
->sin_addr
.s_addr
!= 0) {
3291 (void) printf("broadcast %s",
3292 inet_ntoa(sin
->sin_addr
));
3295 /* If there is a groupname, print it for only the physical interface */
3296 if (strchr(name
, ':') == NULL
) {
3297 if (ioctl(s
, SIOCGLIFGROUPNAME
, &lifr
) >= 0 &&
3298 lifr
.lifr_groupname
[0] != '\0') {
3299 (void) printf("\n\tgroupname %s", lifr
.lifr_groupname
);
3302 (void) putchar('\n');
3306 in6_status(int force
, uint64_t flags
)
3308 char abuf
[INET6_ADDRSTRLEN
];
3309 struct sockaddr_in6
*sin6
, *laddr6
;
3312 (void) printf("in6_status(%s) flags 0x%llx\n", name
, flags
);
3314 if (!(flags
& IFF_IPV6
))
3317 if (!(flags
& IFF_NOLOCAL
)) {
3318 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3319 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
3320 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3324 (void) memset(&lifr
.lifr_addr
, 0,
3325 sizeof (lifr
.lifr_addr
));
3327 Perror0_exit("in_status6: SIOCGLIFADDR");
3329 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3330 (void) printf("\tinet6 %s/%d ",
3331 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3332 abuf
, sizeof (abuf
)),
3336 (void) printf("\tinet6 ");
3338 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3339 if (ioctl(s
, SIOCGLIFSUBNET
, (caddr_t
)&lifr
) < 0) {
3340 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3344 (void) memset(&lifr
.lifr_addr
, 0,
3345 sizeof (lifr
.lifr_addr
));
3347 Perror0_exit("in_status6: SIOCGLIFSUBNET");
3349 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3350 if ((flags
& IFF_NOLOCAL
) ||
3351 !IN6_ARE_ADDR_EQUAL(&sin6
->sin6_addr
, &laddr6
->sin6_addr
)) {
3352 (void) printf("subnet %s/%d ",
3353 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3354 abuf
, sizeof (abuf
)),
3357 if (sin6
->sin6_family
!= AF_INET6
) {
3358 (void) printf("Wrong family: %d\n", sin6
->sin6_family
);
3360 if (flags
& IFF_POINTOPOINT
) {
3361 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3362 if (ioctl(s
, SIOCGLIFDSTADDR
, (caddr_t
)&lifr
) < 0) {
3363 if (errno
== EADDRNOTAVAIL
)
3364 (void) memset(&lifr
.lifr_addr
, 0,
3365 sizeof (lifr
.lifr_addr
));
3367 Perror0_exit("in_status6: SIOCGLIFDSTADDR");
3369 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_dstaddr
;
3370 (void) printf("--> %s ",
3371 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3372 abuf
, sizeof (abuf
)));
3375 (void) putchar('\n');
3376 (void) putchar('\t');
3377 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3378 if (ioctl(s
, SIOCGLIFTOKEN
, (caddr_t
)&lifr
) < 0) {
3379 if (errno
== EADDRNOTAVAIL
|| errno
== EINVAL
)
3380 (void) memset(&lifr
.lifr_addr
, 0,
3381 sizeof (lifr
.lifr_addr
));
3383 Perror0_exit("in_status6: SIOCGLIFTOKEN");
3385 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3386 (void) printf("token %s/%d ",
3387 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3388 abuf
, sizeof (abuf
)),
3391 if (ioctl(s
, SIOCGLIFLNKINFO
, (caddr_t
)&lifr
) < 0) {
3392 if (errno
!= EINVAL
) {
3393 Perror0_exit("in_status6: SIOCGLIFLNKINFO");
3396 (void) printf("maxhops %u, reachtime %u ms, "
3397 "reachretrans %u ms, maxmtu %u ",
3398 lifr
.lifr_ifinfo
.lir_maxhops
,
3399 lifr
.lifr_ifinfo
.lir_reachtime
,
3400 lifr
.lifr_ifinfo
.lir_reachretrans
,
3401 lifr
.lifr_ifinfo
.lir_maxmtu
);
3404 /* If there is a groupname, print it for only the physical interface */
3405 if (strchr(name
, ':') == NULL
) {
3406 if (ioctl(s
, SIOCGLIFGROUPNAME
, &lifr
) >= 0 &&
3407 lifr
.lifr_groupname
[0] != '\0') {
3408 (void) printf("\n\tgroupname %s", lifr
.lifr_groupname
);
3411 (void) putchar('\n');
3415 in_configinfo(int force
, uint64_t flags
)
3417 struct sockaddr_in
*sin
, *laddr
;
3418 struct sockaddr_in netmask
= { AF_INET
};
3421 (void) printf("in_configinfo(%s) flags 0x%llx\n", name
, flags
);
3423 /* only configinfo info for IPv4 interfaces */
3424 if (!(flags
& IFF_IPV4
))
3427 if (!(flags
& IFF_NOLOCAL
)) {
3428 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3429 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
3430 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3434 (void) memset(&lifr
.lifr_addr
, 0,
3435 sizeof (lifr
.lifr_addr
));
3437 Perror0_exit("in_configinfo: SIOCGLIFADDR");
3439 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3440 (void) printf(" set %s ", inet_ntoa(sin
->sin_addr
));
3444 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3445 if (ioctl(s
, SIOCGLIFSUBNET
, (caddr_t
)&lifr
) < 0) {
3446 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3450 (void) memset(&lifr
.lifr_addr
, 0,
3451 sizeof (lifr
.lifr_addr
));
3453 Perror0_exit("in_configinfo: SIOCGLIFSUBNET");
3456 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3458 if ((flags
& IFF_NOLOCAL
) ||
3459 sin
->sin_addr
.s_addr
!= laddr
->sin_addr
.s_addr
) {
3460 (void) printf(" subnet %s/%d ", inet_ntoa(sin
->sin_addr
),
3463 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3464 if (ioctl(s
, SIOCGLIFNETMASK
, (caddr_t
)&lifr
) < 0) {
3465 if (errno
!= EADDRNOTAVAIL
)
3466 Perror0_exit("in_configinfo: SIOCGLIFNETMASK");
3467 (void) memset(&lifr
.lifr_addr
, 0, sizeof (lifr
.lifr_addr
));
3470 ((struct sockaddr_in
*)&lifr
.lifr_addr
)->sin_addr
;
3471 if (flags
& IFF_POINTOPOINT
) {
3472 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3473 if (ioctl(s
, SIOCGLIFDSTADDR
, (caddr_t
)&lifr
) < 0) {
3474 if (errno
== EADDRNOTAVAIL
)
3475 (void) memset(&lifr
.lifr_addr
, 0,
3476 sizeof (lifr
.lifr_addr
));
3478 Perror0_exit("in_configinfo: SIOCGLIFDSTADDR");
3480 sin
= (struct sockaddr_in
*)&lifr
.lifr_dstaddr
;
3481 (void) printf(" destination %s ", inet_ntoa(sin
->sin_addr
));
3483 (void) printf(" netmask 0x%x ", ntohl(netmask
.sin_addr
.s_addr
));
3484 if (flags
& IFF_BROADCAST
) {
3485 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3486 if (ioctl(s
, SIOCGLIFBRDADDR
, (caddr_t
)&lifr
) < 0) {
3487 if (errno
== EADDRNOTAVAIL
)
3488 (void) memset(&lifr
.lifr_addr
, 0,
3489 sizeof (lifr
.lifr_addr
));
3491 Perror0_exit("in_configinfo: SIOCGLIFBRDADDR");
3493 sin
= (struct sockaddr_in
*)&lifr
.lifr_addr
;
3494 if (sin
->sin_addr
.s_addr
!= 0) {
3495 (void) printf(" broadcast %s ",
3496 inet_ntoa(sin
->sin_addr
));
3500 /* If there is a groupname, print it for only the zeroth interface */
3501 if (lifnum(name
) == 0) {
3502 if (ioctl(s
, SIOCGLIFGROUPNAME
, &lifr
) >= 0 &&
3503 lifr
.lifr_groupname
[0] != '\0') {
3504 (void) printf(" group %s ", lifr
.lifr_groupname
);
3508 /* Print flags to configure */
3509 print_config_flags(AF_INET
, flags
);
3513 in6_configinfo(int force
, uint64_t flags
)
3515 char abuf
[INET6_ADDRSTRLEN
];
3516 struct sockaddr_in6
*sin6
, *laddr6
;
3519 (void) printf("in6_configinfo(%s) flags 0x%llx\n", name
,
3522 if (!(flags
& IFF_IPV6
))
3525 if (!(flags
& IFF_NOLOCAL
)) {
3526 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3527 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
3528 if (errno
== EADDRNOTAVAIL
|| errno
== EAFNOSUPPORT
||
3532 (void) memset(&lifr
.lifr_addr
, 0,
3533 sizeof (lifr
.lifr_addr
));
3535 Perror0_exit("in6_configinfo: SIOCGLIFADDR");
3537 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3538 (void) printf(" set %s/%d ",
3539 inet_ntop(AF_INET6
, &sin6
->sin6_addr
, abuf
, sizeof (abuf
)),
3543 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3544 if (ioctl(s
, SIOCGLIFSUBNET
, (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: SIOCGLIFSUBNET");
3554 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3555 if ((flags
& IFF_NOLOCAL
) ||
3556 !IN6_ARE_ADDR_EQUAL(&sin6
->sin6_addr
, &laddr6
->sin6_addr
)) {
3557 (void) printf(" subnet %s/%d ",
3558 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3559 abuf
, sizeof (abuf
)),
3563 if (flags
& IFF_POINTOPOINT
) {
3564 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3565 if (ioctl(s
, SIOCGLIFDSTADDR
, (caddr_t
)&lifr
) < 0) {
3566 if (errno
== EADDRNOTAVAIL
)
3567 (void) memset(&lifr
.lifr_addr
, 0,
3568 sizeof (lifr
.lifr_addr
));
3570 Perror0_exit("in6_configinfo: SIOCGLIFDSTADDR");
3572 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_dstaddr
;
3573 (void) printf(" destination %s ",
3574 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3575 abuf
, sizeof (abuf
)));
3578 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
3579 if (ioctl(s
, SIOCGLIFTOKEN
, (caddr_t
)&lifr
) < 0) {
3580 if (errno
== EADDRNOTAVAIL
|| errno
== EINVAL
)
3581 (void) memset(&lifr
.lifr_addr
, 0,
3582 sizeof (lifr
.lifr_addr
));
3584 Perror0_exit("in6_configinfo: SIOCGLIFTOKEN");
3586 sin6
= (struct sockaddr_in6
*)&lifr
.lifr_addr
;
3587 (void) printf(" token %s/%d ",
3588 inet_ntop(AF_INET6
, (void *)&sin6
->sin6_addr
,
3589 abuf
, sizeof (abuf
)),
3593 /* If there is a groupname, print it for only the zeroth interface */
3594 if (lifnum(name
) == 0) {
3595 if (ioctl(s
, SIOCGLIFGROUPNAME
, &lifr
) >= 0 &&
3596 lifr
.lifr_groupname
[0] != '\0') {
3597 (void) printf(" group %s ", lifr
.lifr_groupname
);
3601 /* Print flags to configure */
3602 print_config_flags(AF_INET6
, flags
);
3606 * If this is a physical interface then remove it.
3607 * If it is a logical interface name use SIOCLIFREMOVEIF to
3608 * remove it. In both cases fail if it doesn't exist.
3612 inetunplumb(char *arg
, int64_t param
)
3614 ipadm_status_t istatus
;
3616 istatus
= ipadm_delete_if(iph
, name
, afp
->af_af
, IPADM_OPT_ACTIVE
);
3617 if (istatus
!= IPADM_SUCCESS
) {
3618 (void) fprintf(stderr
, "ifconfig: cannot unplumb %s: %s\n",
3619 name
, ipadm_status2str(istatus
));
3627 * Create the interface in `name', using ipadm_create_if(). If `name' is a
3628 * logical interface or loopback interface, ipadm_create_if() uses
3629 * SIOCLIFADDIF to create it.
3633 inetplumb(char *arg
, int64_t param
)
3635 ipadm_status_t istatus
;
3637 istatus
= ipadm_create_if(iph
, name
, afp
->af_af
, IPADM_OPT_ACTIVE
);
3638 if (istatus
!= IPADM_SUCCESS
) {
3639 (void) fprintf(stderr
, "ifconfig: cannot plumb %s: %s\n",
3640 name
, ipadm_status2str(istatus
));
3641 if (istatus
!= IPADM_IF_EXISTS
)
3649 inetipmp(char *arg
, int64_t param
)
3654 * Treat e.g. "ifconfig ipmp0:2 ipmp" as "ifconfig ipmp0:2 plumb".
3655 * Otherwise, try to create the requested IPMP interface.
3657 if (strchr(name
, ':') != NULL
)
3658 retval
= inetplumb(arg
, param
);
3660 retval
= create_ipmp(name
, afp
->af_af
, name
, _B_FALSE
);
3663 * We'd return -1, but foreachinterface() doesn't propagate the error
3664 * into the exit status, so we're forced to explicitly exit().
3672 * Create an IPMP group `grname' with address family `af'. If `ifname' is
3673 * non-NULL, it specifies the interface name to use. Otherwise, use the name
3674 * ipmpN, where N corresponds to the lowest available integer. If `implicit'
3675 * is set, then the group is being created as a side-effect of placing an
3676 * underlying interface in a group. Also start in.mpathd if necessary.
3679 create_ipmp(const char *grname
, int af
, const char *ifname
, boolean_t implicit
)
3681 static int ipmp_daemon_started
;
3682 uint32_t flags
= IPADM_OPT_IPMP
|IPADM_OPT_ACTIVE
;
3683 ipadm_status_t istatus
;
3686 (void) printf("create_ipmp: ifname %s grname %s af %d\n",
3687 ifname
!= NULL
? ifname
: "NULL", grname
, af
);
3691 * ipadm_create_if() creates the IPMP interface and fills in the
3692 * ppa in lifr.lifr_name, if `ifname'="ipmp".
3694 (void) strlcpy(lifr
.lifr_name
, (ifname
? ifname
: "ipmp"),
3695 sizeof (lifr
.lifr_name
));
3697 flags
|= IPADM_OPT_GENPPA
;
3698 istatus
= ipadm_create_if(iph
, lifr
.lifr_name
, af
, flags
);
3699 if (istatus
!= IPADM_SUCCESS
) {
3700 (void) fprintf(stderr
, "ifconfig: cannot create IPMP interface "
3701 "%s: %s\n", grname
, ipadm_status2str(istatus
));
3706 * To preserve backward-compatibility, always bring up the link-local
3707 * address for implicitly-created IPv6 IPMP interfaces.
3709 if (implicit
&& af
== AF_INET6
) {
3710 if (ioctl(s6
, SIOCGLIFFLAGS
, &lifr
) == 0) {
3711 lifr
.lifr_flags
|= IFF_UP
;
3712 (void) ioctl(s6
, SIOCSLIFFLAGS
, &lifr
);
3717 * If the caller requested a different group name, issue a
3718 * SIOCSLIFGROUPNAME on the new IPMP interface.
3720 if (strcmp(lifr
.lifr_name
, grname
) != 0) {
3721 (void) strlcpy(lifr
.lifr_groupname
, grname
, LIFGRNAMSIZ
);
3722 if (ioctl(s
, SIOCSLIFGROUPNAME
, &lifr
) == -1) {
3723 Perror0("SIOCSLIFGROUPNAME");
3729 * If we haven't done so yet, ensure in.mpathd is started.
3731 if (ipmp_daemon_started
++ == 0)
3732 start_ipmp_daemon();
3738 * Start in.mpathd if it's not already running.
3741 start_ipmp_daemon(void)
3744 ipmp_handle_t ipmp_handle
;
3747 * Ping in.mpathd to see if it's running already.
3749 if ((retval
= ipmp_open(&ipmp_handle
)) != IPMP_SUCCESS
) {
3750 (void) fprintf(stderr
, "ifconfig: cannot create IPMP handle: "
3751 "%s\n", ipmp_errmsg(retval
));
3755 retval
= ipmp_ping_daemon(ipmp_handle
);
3756 ipmp_close(ipmp_handle
);
3759 case IPMP_ENOMPATHD
:
3764 (void) fprintf(stderr
, "ifconfig: cannot ping in.mpathd: %s\n",
3765 ipmp_errmsg(retval
));
3770 * Start in.mpathd. Note that in.mpathd will handle multiple
3771 * incarnations (ipmp_ping_daemon() is just an optimization) so we
3772 * don't need to worry about racing with another ifconfig process.
3776 Perror0_exit("start_ipmp_daemon: fork");
3779 (void) execl(MPATHD_PATH
, MPATHD_PATH
, NULL
);
3788 * Bring the address named by `ifaddrp' up or down. Doesn't trust any mutable
3789 * values in ia_flags since they may be stale.
3792 ifaddr_op(ifaddrlistx_t
*ifaddrp
, boolean_t up
)
3794 struct lifreq lifrl
; /* Local lifreq struct */
3795 int fd
= (ifaddrp
->ia_flags
& IFF_IPV4
) ? s4
: s6
;
3797 (void) memset(&lifrl
, 0, sizeof (lifrl
));
3798 (void) strlcpy(lifrl
.lifr_name
, ifaddrp
->ia_name
, LIFNAMSIZ
);
3799 if (ioctl(fd
, SIOCGLIFFLAGS
, &lifrl
) == -1)
3803 lifrl
.lifr_flags
|= IFF_UP
;
3805 lifrl
.lifr_flags
&= ~IFF_UP
;
3807 if (ioctl(fd
, SIOCSLIFFLAGS
, &lifrl
) == -1)
3811 * If we're trying to bring the address down, ensure that DAD activity
3812 * (observable by IFF_DUPLICATE) has also been stopped.
3814 if (!up
&& ioctl(fd
, SIOCGLIFFLAGS
, &lifrl
) != -1 &&
3815 lifrl
.lifr_flags
& IFF_DUPLICATE
) {
3816 if (ioctl(fd
, SIOCGLIFADDR
, &lifrl
) == -1 ||
3817 ioctl(fd
, SIOCSLIFADDR
, &lifrl
) == -1) {
3825 ifaddr_up(ifaddrlistx_t
*ifaddrp
)
3827 return (ifaddr_op(ifaddrp
, _B_TRUE
));
3831 ifaddr_down(ifaddrlistx_t
*ifaddrp
)
3833 return (ifaddr_op(ifaddrp
, _B_FALSE
));
3837 * Open the global libdladm handle "dlh" if it isn't already opened. The
3838 * caller may optionally supply a link name to obtain its linkid. If a link
3839 * of a specific class or classes is required, reqclass specifies the class
3842 static dladm_status_t
3843 ifconfig_dladm_open(const char *name
, datalink_class_t reqclass
,
3844 datalink_id_t
*linkid
)
3846 dladm_status_t status
= DLADM_STATUS_OK
;
3847 datalink_class_t
class;
3850 if ((status
= dladm_open(&dlh
)) != DLADM_STATUS_OK
)
3852 dlh_opened
= _B_TRUE
;
3855 status
= dladm_name2info(dlh
, name
, linkid
, NULL
, &class, NULL
);
3856 if (status
== DLADM_STATUS_OK
) {
3857 if (!(class & reqclass
))
3858 status
= DLADM_STATUS_LINKINVAL
;
3865 * This function checks if we can use libipadm API's. We will only
3866 * call libipadm functions for non-IPMP interfaces. This check is
3867 * temporary until libipadm supports IPMP interfaces.
3870 ifconfig_use_libipadm(int s
, const char *lifname
)
3872 struct lifreq lifr1
;
3874 (void) strlcpy(lifr1
.lifr_name
, lifname
, sizeof (lifr1
.lifr_name
));
3875 if (ioctl(s
, SIOCGLIFGROUPNAME
, (caddr_t
)&lifr1
) < 0) {
3876 (void) strncpy(lifr
.lifr_name
, lifname
,
3877 sizeof (lifr
.lifr_name
));
3878 Perror0_exit("error");
3881 return (lifr1
.lifr_groupname
[0] == '\0');
3885 ipadmerr_exit(ipadm_status_t status
, const char *str
)
3887 (void) fprintf(stderr
, "ifconfig: %s: %s\n", str
,
3888 ipadm_status2str(status
));
3893 dladmerr_exit(dladm_status_t status
, const char *str
)
3895 char errstr
[DLADM_STRSIZE
];
3897 (void) fprintf(stderr
, "%s: %s\n", str
,
3898 dladm_status2str(status
, errstr
));
3903 Perror0(const char *cmd
)
3905 Perror2(cmd
, lifr
.lifr_name
);
3909 Perror0_exit(const char *cmd
)
3916 Perror2(const char *cmd
, const char *str
)
3920 (void) fprintf(stderr
, "ifconfig: %s: ", cmd
);
3924 (void) fprintf(stderr
, "%s: no such interface\n", str
);
3927 (void) fprintf(stderr
, "%s: permission denied\n", str
);
3930 (void) fprintf(stderr
, "%s: already exists\n", str
);
3933 (void) fprintf(stderr
, "%s: interface name too long\n", str
);
3936 (void) fprintf(stderr
, "%s: logical interface id is outside "
3937 "allowed range\n", str
);
3946 * Print out error message (Perror2()) and exit
3949 Perror2_exit(const char *cmd
, const char *str
)
3957 Perrdlpi(const char *cmd
, const char *linkname
, int err
)
3959 (void) fprintf(stderr
, "ifconfig: %s \"%s\": %s\n", cmd
,
3960 linkname
, dlpi_strerror(err
));
3964 * Print out error message (Perrdlpi()) and exit
3967 Perrdlpi_exit(const char *cmd
, const char *linkname
, int err
)
3969 Perrdlpi(cmd
, linkname
, err
);
3974 * If the last argument is non-NULL allow a <addr>/<n> syntax and
3975 * pass out <n> in *plenp.
3976 * If <n> doesn't parse return BAD_ADDR as *plenp.
3977 * If no /<n> is present return NO_PREFIX as *plenp.
3980 in_getaddr(char *s
, struct sockaddr
*saddr
, int *plenp
)
3982 /* LINTED: alignment */
3983 struct sockaddr_in
*sin
= (struct sockaddr_in
*)saddr
;
3989 (void) strncpy(str
, s
, sizeof (str
));
3992 * Look for '/'<n> is plenp
3994 if (plenp
!= NULL
) {
3997 *plenp
= in_getprefixlen(str
, _B_TRUE
, IP_ABITS
);
3998 if (*plenp
== BAD_ADDR
)
4000 cp
= strchr(str
, '/');
4003 } else if (strchr(str
, '/') != NULL
) {
4004 (void) fprintf(stderr
, "ifconfig: %s: unexpected '/'\n", str
);
4008 (void) memset(sin
, 0, sizeof (*sin
));
4011 * Try to catch attempts to set the broadcast address to all 1's.
4013 if (strcmp(str
, "255.255.255.255") == 0 ||
4014 (strtoul(str
, (char **)NULL
, 0) == 0xffffffffUL
)) {
4015 sin
->sin_family
= AF_INET
;
4016 sin
->sin_addr
.s_addr
= 0xffffffff;
4020 hp
= getipnodebyname(str
, AF_INET
, 0, &error_num
);
4022 sin
->sin_family
= hp
->h_addrtype
;
4023 (void) memcpy(&sin
->sin_addr
, hp
->h_addr
, hp
->h_length
);
4027 np
= getnetbyname(str
);
4029 sin
->sin_family
= np
->n_addrtype
;
4030 sin
->sin_addr
= inet_makeaddr(np
->n_net
, INADDR_ANY
);
4033 if (error_num
== TRY_AGAIN
) {
4034 (void) fprintf(stderr
, "ifconfig: %s: bad address "
4035 "(try again later)\n", s
);
4037 (void) fprintf(stderr
, "ifconfig: %s: bad address\n", s
);
4043 * If the last argument is non-NULL allow a <addr>/<n> syntax and
4044 * pass out <n> in *plenp.
4045 * If <n> doesn't parse return BAD_ADDR as *plenp.
4046 * If no /<n> is present return NO_PREFIX as *plenp.
4049 in6_getaddr(char *s
, struct sockaddr
*saddr
, int *plenp
)
4051 /* LINTED: alignment */
4052 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)saddr
;
4057 (void) strncpy(str
, s
, sizeof (str
));
4060 * Look for '/'<n> is plenp
4062 if (plenp
!= NULL
) {
4065 *plenp
= in_getprefixlen(str
, _B_TRUE
, IPV6_ABITS
);
4066 if (*plenp
== BAD_ADDR
)
4068 cp
= strchr(str
, '/');
4071 } else if (strchr(str
, '/') != NULL
) {
4072 (void) fprintf(stderr
, "ifconfig: %s: unexpected '/'\n", str
);
4076 (void) memset(sin6
, 0, sizeof (*sin6
));
4078 hp
= getipnodebyname(str
, AF_INET6
, 0, &error_num
);
4080 sin6
->sin6_family
= hp
->h_addrtype
;
4081 (void) memcpy(&sin6
->sin6_addr
, hp
->h_addr
, hp
->h_length
);
4085 if (error_num
== TRY_AGAIN
) {
4086 (void) fprintf(stderr
, "ifconfig: %s: bad address "
4087 "(try again later)\n", s
);
4089 (void) fprintf(stderr
, "ifconfig: %s: bad address\n", s
);
4095 * If "slash" is zero this parses the whole string as
4096 * an integer. With "slash" non zero it parses the tail part as an integer.
4098 * If it is not a valid integer this returns BAD_ADDR.
4099 * If there is /<n> present this returns NO_PREFIX.
4102 in_getprefixlen(char *addr
, boolean_t slash
, int max_plen
)
4108 str
= strchr(addr
, '/');
4115 prefixlen
= strtol(str
, &end
, 10);
4120 if (max_plen
!= 0 && max_plen
< prefixlen
)
4126 * Convert a prefix length to a mask.
4127 * Returns 1 if ok. 0 otherwise.
4128 * Assumes the mask array is zero'ed by the caller.
4131 in_prefixlentomask(int prefixlen
, int maxlen
, uchar_t
*mask
)
4133 if (prefixlen
< 0 || prefixlen
> maxlen
)
4136 while (prefixlen
> 0) {
4137 if (prefixlen
>= 8) {
4142 *mask
|= 1 << (8 - prefixlen
);
4149 print_flags(uint64_t flags
)
4151 boolean_t first
= _B_TRUE
;
4154 (void) printf("flags=%llx", flags
);
4155 cnt
= sizeof (if_flags_tbl
) / sizeof (if_flags_t
);
4156 for (i
= 0; i
< cnt
; i
++) {
4157 if (flags
& if_flags_tbl
[i
].iff_value
) {
4163 * It has to be here and not with the
4164 * printf below because for the last one,
4165 * we don't want a comma before the ">".
4169 (void) printf("%s", if_flags_tbl
[i
].iff_name
);
4177 print_config_flags(int af
, uint64_t flags
)
4179 if_config_cmd_t
*cmdp
;
4181 for (cmdp
= if_config_cmd_tbl
; cmdp
->iff_flag
!= 0; cmdp
++) {
4182 if ((flags
& cmdp
->iff_flag
) &&
4183 (cmdp
->iff_af
== AF_UNSPEC
|| cmdp
->iff_af
== af
)) {
4184 (void) printf("%s ", cmdp
->iff_name
);
4190 * Use the configured directory lookup mechanism (e.g. files/NIS/...)
4191 * to find the network mask. Returns true if we found one to set.
4193 * The parameter addr_set controls whether we should get the address of
4194 * the working interface for the netmask query. If addr_set is true,
4195 * we will use the address provided. Otherwise, we will find the working
4196 * interface's address and use it instead.
4199 in_getmask(struct sockaddr_in
*saddr
, boolean_t addr_set
)
4201 struct sockaddr_in ifaddr
;
4204 * Read the address from the interface if it is not passed in.
4207 (void) strncpy(lifr
.lifr_name
, name
, sizeof (lifr
.lifr_name
));
4208 if (ioctl(s
, SIOCGLIFADDR
, (caddr_t
)&lifr
) < 0) {
4209 if (errno
!= EADDRNOTAVAIL
) {
4210 (void) fprintf(stderr
, "Need net number for "
4215 ifaddr
= *((struct sockaddr_in
*)&lifr
.lifr_addr
);
4217 ifaddr
.sin_addr
= saddr
->sin_addr
;
4219 if (getnetmaskbyaddr(ifaddr
.sin_addr
, &saddr
->sin_addr
) == 0) {
4220 saddr
->sin_family
= AF_INET
;
4227 lifnum(const char *ifname
)
4231 if ((cp
= strchr(ifname
, ':')) == NULL
)
4234 return (atoi(cp
+ 1));
4238 add_ni(const char *name
)
4243 for (pp
= &ni_list
; (p
= *pp
) != NULL
; pp
= &(p
->ni_next
)) {
4244 if (strcmp(p
->ni_name
, name
) == 0) {
4246 (void) fprintf(stderr
, "'%s' is a duplicate\n",
4253 (void) fprintf(stderr
, "adding '%s'\n",
4256 if ((p
= malloc(sizeof (ni_t
))) == NULL
)
4259 (void) strlcpy(p
->ni_name
, name
, sizeof (p
->ni_name
));
4267 ni_entry(const char *linkname
, void *arg
)
4270 datalink_class_t
class;
4272 (void) dladm_name2info(arg
, linkname
, NULL
, NULL
, &class, NULL
);
4274 if (class == DATALINK_CLASS_ETHERSTUB
)
4276 if (dlpi_open(linkname
, &dh
, 0) != DLPI_SUCCESS
)
4286 * dhcp-related routines
4290 setifdhcp(const char *caller
, const char *ifname
, int argc
, char *argv
[])
4292 dhcp_ipc_request_t
*request
;
4293 dhcp_ipc_reply_t
*reply
= NULL
;
4294 int timeout
= DHCP_IPC_WAIT_DEFAULT
;
4295 dhcp_ipc_type_t type
= DHCP_START
;
4297 boolean_t is_primary
= _B_FALSE
;
4298 boolean_t started
= _B_FALSE
;
4300 for (argv
++; --argc
> 0; argv
++) {
4302 if (strcmp(*argv
, "primary") == 0) {
4303 is_primary
= _B_TRUE
;
4307 if (strcmp(*argv
, "wait") == 0) {
4310 return (DHCP_EXIT_BADARGS
);
4314 if (strcmp(*argv
, "forever") == 0) {
4315 timeout
= DHCP_IPC_WAIT_FOREVER
;
4319 if (sscanf(*argv
, "%d", &timeout
) != 1) {
4321 return (DHCP_EXIT_BADARGS
);
4326 return (DHCP_EXIT_BADARGS
);
4331 type
= dhcp_string_to_request(*argv
);
4334 return (DHCP_EXIT_BADARGS
);
4339 * Only try to start agent on start or inform; in all other cases it
4340 * has to already be running for anything to make sense.
4342 if (type
== DHCP_START
|| type
== DHCP_INFORM
) {
4343 if (dhcp_start_agent(DHCP_IPC_MAX_WAIT
) == -1) {
4344 (void) fprintf(stderr
, "%s: unable to start %s\n",
4345 caller
, DHCP_AGENT_PATH
);
4346 return (DHCP_EXIT_FAILURE
);
4352 type
|= DHCP_PRIMARY
;
4357 request
= dhcp_ipc_alloc_request(type
, ifname
, NULL
, 0, DHCP_TYPE_NONE
);
4358 if (request
== NULL
) {
4359 (void) fprintf(stderr
, "%s: out of memory\n", caller
);
4360 return (DHCP_EXIT_SYSTEM
);
4363 error
= dhcp_ipc_make_request(request
, &reply
, timeout
);
4367 * Re-map connect error to not under control if we didn't try a
4368 * start operation, as this has to be true and results in a
4369 * clearer message, not to mention preserving compatibility
4370 * with the days when we always started dhcpagent for every
4373 if (error
== DHCP_IPC_E_CONNECT
&& !started
)
4374 error
= DHCP_IPC_E_UNKIF
;
4375 (void) fprintf(stderr
, "%s: %s: %s\n", caller
, ifname
,
4376 dhcp_ipc_strerror(error
));
4377 return (DHCP_EXIT_FAILURE
);
4380 error
= reply
->return_code
;
4385 if (error
== DHCP_IPC_E_TIMEOUT
&& timeout
== 0)
4386 return (DHCP_EXIT_SUCCESS
);
4388 (void) fprintf(stderr
, "%s: %s: %s\n", caller
, ifname
,
4389 dhcp_ipc_strerror(error
));
4391 if (error
== DHCP_IPC_E_TIMEOUT
)
4392 return (DHCP_EXIT_TIMEOUT
);
4394 return (DHCP_EXIT_IF_FAILURE
);
4397 if (DHCP_IPC_CMD(type
) == DHCP_STATUS
) {
4398 (void) printf("%s", dhcp_status_hdr_string());
4399 (void) printf("%s", dhcp_status_reply_to_string(reply
));
4404 return (DHCP_EXIT_SUCCESS
);
4410 (void) fprintf(stderr
,
4411 "usage: ifconfig <interface> | -a[ 4 | 6 | D ][ u | d ][ Z ]\n");
4413 (void) fprintf(stderr
, "%s",
4414 "\t[ <addr_family> ]\n"
4415 "\t[ <address>[/<prefix_length>] [ <dest_address> ] ]\n"
4416 "\t[ set [ <address>][/<prefix_length>] ]"
4417 " [ <address>/<prefix_length>] ]\n"
4418 "\t[ destination <dest_address> ]\n"
4419 "\t[ addif <address>[/<prefix_length>]"
4420 " [ <dest_address> ] ]\n"
4421 "\t[ removeif <address>[/<prefix_length>] ]\n"
4422 "\t[ arp | -arp ]\n"
4423 "\t[ auto-revarp ]\n"
4424 "\t[ broadcast <broad_addr> ]\n"
4425 "\t[ index <if_index> ]\n"
4426 "\t[ metric <n> ] [ mtu <n> ]\n"
4427 "\t[ netmask <mask> ]\n"
4428 "\t[ plumb ] [ unplumb ]\n"
4429 "\t[ preferred | -preferred ]\n"
4430 "\t[ private | -private ]\n"
4431 "\t[ local | -local ]\n"
4432 "\t[ router | -router ]\n"
4433 "\t[ subnet <subnet_address>]\n"
4434 "\t[ trailers | -trailers ]\n"
4435 "\t[ token <address>/<prefix_length> ]\n"
4436 "\t[ tsrc <tunnel_src_address> ]\n"
4437 "\t[ tdst <tunnel_dest_address> ]\n"
4438 "\t[ auth_algs <tunnel_AH_authentication_algorithm> ]\n"
4439 "\t[ encr_algs <tunnel_ESP_encryption_algorithm> ]\n"
4440 "\t[ encr_auth_algs <tunnel_ESP_authentication_algorithm> ]\n"
4441 "\t[ up ] [ down ]\n"
4442 "\t[ xmit | -xmit ]\n"
4444 "\t[ modinsert <module_name@position> ]\n"
4445 "\t[ modremove <module_name@position> ]\n"
4447 "\t[ group <groupname>] | [ group \"\"]\n"
4448 "\t[ deprecated | -deprecated ]\n"
4449 "\t[ standby | -standby ]\n"
4450 "\t[ failover | -failover ]\n"
4451 "\t[ zone <zonename> | -zone ]\n"
4452 "\t[ usesrc <interface> ]\n");
4454 (void) fprintf(stderr
, "or\n");
4455 (void) fprintf(stderr
,
4456 "\tifconfig <interface> | -a[ 4 | 6 | D ] [ u | d ]\n");
4458 (void) fprintf(stderr
, "%s", "\tauto-dhcp | dhcp\n"
4459 "\t[ wait <time> | forever ]\n\t[ primary ]\n"
4460 "\tstart | drop | ping | release | status | inform\n");