1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-26 06:35:07 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1996-11-21 19:36:09 +00:00
|
|
|
static const char copyright[] =
|
1994-05-26 06:35:07 +00:00
|
|
|
"@(#) Copyright (c) 1983, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1998-07-06 06:53:43 +00:00
|
|
|
#if 0
|
1994-05-26 06:35:07 +00:00
|
|
|
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
|
1998-07-06 06:53:43 +00:00
|
|
|
#endif
|
1996-11-21 19:36:09 +00:00
|
|
|
static const char rcsid[] =
|
1999-08-28 00:22:10 +00:00
|
|
|
"$FreeBSD$";
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
1999-09-20 07:58:08 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/linker.h>
|
2015-02-02 13:03:04 +00:00
|
|
|
#include <sys/queue.h>
|
2015-09-27 07:51:18 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/time.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2000-06-16 20:14:43 +00:00
|
|
|
#include <net/ethernet.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <net/if.h>
|
1994-12-30 22:42:41 +00:00
|
|
|
#include <net/if_dl.h>
|
1996-01-01 09:05:22 +00:00
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/route.h>
|
1996-11-21 19:36:09 +00:00
|
|
|
|
|
|
|
/* IP */
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <netinet/in.h>
|
1994-12-30 22:42:41 +00:00
|
|
|
#include <netinet/in_var.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <arpa/inet.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
|
2007-02-24 23:55:46 +00:00
|
|
|
#include <ifaddrs.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
1996-11-21 19:36:09 +00:00
|
|
|
#include <fcntl.h>
|
2012-02-14 07:14:42 +00:00
|
|
|
#ifdef JAIL
|
2009-06-24 18:21:37 +00:00
|
|
|
#include <jail.h>
|
2012-02-14 07:14:42 +00:00
|
|
|
#endif
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1997-05-04 06:27:45 +00:00
|
|
|
#include "ifconfig.h"
|
|
|
|
|
2004-08-09 03:13:57 +00:00
|
|
|
/*
|
|
|
|
* Since "struct ifreq" is composed of various union members, callers
|
2014-08-12 19:37:49 +00:00
|
|
|
* should pay special attention to interpret the value.
|
2004-08-09 03:13:57 +00:00
|
|
|
* (.e.g. little/big endian difference in the structure.)
|
|
|
|
*/
|
2004-12-08 19:18:07 +00:00
|
|
|
struct ifreq ifr;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2004-01-27 01:43:14 +00:00
|
|
|
char name[IFNAMSIZ];
|
2010-01-27 00:30:07 +00:00
|
|
|
char *descr = NULL;
|
|
|
|
size_t descrlen = 64;
|
1994-05-26 06:35:07 +00:00
|
|
|
int setaddr;
|
2001-07-26 16:44:19 +00:00
|
|
|
int setmask;
|
1994-05-26 06:35:07 +00:00
|
|
|
int doalias;
|
|
|
|
int clearaddr;
|
|
|
|
int newaddr = 1;
|
2004-12-08 19:18:07 +00:00
|
|
|
int verbose;
|
2007-05-22 17:41:09 +00:00
|
|
|
int noload;
|
2016-02-20 11:36:35 +00:00
|
|
|
int printifname = 0;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
int supmedia = 0;
|
2005-07-14 18:33:21 +00:00
|
|
|
int printkeys = 0; /* Print keying material for interfaces. */
|
1996-11-21 19:36:09 +00:00
|
|
|
|
2016-05-31 17:30:08 +00:00
|
|
|
/* Formatter Strings */
|
2016-06-02 03:16:02 +00:00
|
|
|
char *f_inet, *f_inet6, *f_ether, *f_addr;
|
2016-05-31 17:30:08 +00:00
|
|
|
|
2008-03-31 15:38:07 +00:00
|
|
|
static int ifconfig(int argc, char *const *argv, int iscreate,
|
|
|
|
const struct afswtch *afp);
|
2007-02-24 23:55:46 +00:00
|
|
|
static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
|
|
|
|
struct ifaddrs *ifa);
|
2004-12-08 19:18:07 +00:00
|
|
|
static void tunnel_status(int s);
|
Various Coverity fixes in ifconfig(8)
* Exit early if kldload(2) fails (1011259). This is the only change that
affects ifconfig's behavior.
* Close memory and resource leaks (1305624, 1305205, 1007100)
* Mark usage() as _Noreturn (1305806, 1305750)
* Fix some dereference after null checks (1011474, 270774)
Reported by: Coverity
CID: 1305624, 1305205, 1007100, 1305806, 1305750, 1011474,
CID: 270774, 1011259
Reviewed by: cem
MFC after: 3 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D10587
2017-05-03 17:21:01 +00:00
|
|
|
static void usage(void) _Noreturn;
|
1999-12-07 17:39:16 +00:00
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static struct afswtch *af_getbyname(const char *name);
|
|
|
|
static struct afswtch *af_getbyfamily(int af);
|
2004-12-31 19:46:27 +00:00
|
|
|
static void af_other_status(int);
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2016-02-20 11:36:35 +00:00
|
|
|
void printifnamemaybe(void);
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static struct option *opts = NULL;
|
1996-01-01 09:05:22 +00:00
|
|
|
|
2015-02-02 13:03:04 +00:00
|
|
|
struct ifa_order_elt {
|
|
|
|
int if_order;
|
|
|
|
int af_orders[255];
|
|
|
|
struct ifaddrs *ifa;
|
|
|
|
TAILQ_ENTRY(ifa_order_elt) link;
|
|
|
|
};
|
|
|
|
|
|
|
|
TAILQ_HEAD(ifa_queue, ifa_order_elt);
|
|
|
|
|
1996-01-01 09:05:22 +00:00
|
|
|
void
|
2004-12-08 19:18:07 +00:00
|
|
|
opt_register(struct option *p)
|
1996-01-01 09:05:22 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
p->next = opts;
|
|
|
|
opts = p;
|
1996-01-01 09:05:22 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
usage(void)
|
1997-05-04 06:14:47 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
char options[1024];
|
|
|
|
struct option *p;
|
|
|
|
|
|
|
|
/* XXX not right but close enough for now */
|
|
|
|
options[0] = '\0';
|
|
|
|
for (p = opts; p != NULL; p = p->next) {
|
|
|
|
strlcat(options, p->opt_usage, sizeof(options));
|
|
|
|
strlcat(options, " ", sizeof(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr,
|
2016-05-31 17:30:08 +00:00
|
|
|
"usage: ifconfig [-f type:format] %sinterface address_family\n"
|
|
|
|
" [address [dest_address]] [parameters]\n"
|
2004-12-08 19:18:07 +00:00
|
|
|
" ifconfig interface create\n"
|
|
|
|
" ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n"
|
|
|
|
" ifconfig -l [-d] [-u] [address_family]\n"
|
|
|
|
" ifconfig %s[-d] [-m] [-u] [-v]\n",
|
|
|
|
options, options, options);
|
1997-05-04 06:14:47 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-01-01 09:05:22 +00:00
|
|
|
|
2015-02-02 14:37:45 +00:00
|
|
|
#define ORDERS_SIZE(x) sizeof(x) / sizeof(x[0])
|
|
|
|
|
2015-02-02 13:03:04 +00:00
|
|
|
static int
|
|
|
|
calcorders(struct ifaddrs *ifa, struct ifa_queue *q)
|
|
|
|
{
|
|
|
|
struct ifaddrs *prev;
|
|
|
|
struct ifa_order_elt *cur;
|
2015-02-02 14:37:45 +00:00
|
|
|
unsigned int ord, af, ifa_ord;
|
2015-02-02 13:03:04 +00:00
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
cur = NULL;
|
|
|
|
ord = 0;
|
|
|
|
ifa_ord = 0;
|
|
|
|
|
|
|
|
while (ifa != NULL) {
|
2015-02-02 14:37:45 +00:00
|
|
|
if (prev == NULL ||
|
|
|
|
strcmp(ifa->ifa_name, prev->ifa_name) != 0) {
|
2015-02-02 13:03:04 +00:00
|
|
|
cur = calloc(1, sizeof(*cur));
|
|
|
|
|
|
|
|
if (cur == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(q, cur, link);
|
|
|
|
cur->if_order = ifa_ord ++;
|
|
|
|
cur->ifa = ifa;
|
|
|
|
ord = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifa->ifa_addr) {
|
|
|
|
af = ifa->ifa_addr->sa_family;
|
|
|
|
|
2015-02-02 14:37:45 +00:00
|
|
|
if (af < ORDERS_SIZE(cur->af_orders) &&
|
|
|
|
cur->af_orders[af] == 0)
|
2015-02-02 13:03:04 +00:00
|
|
|
cur->af_orders[af] = ++ord;
|
|
|
|
}
|
|
|
|
prev = ifa;
|
2015-02-02 14:37:45 +00:00
|
|
|
ifa = ifa->ifa_next;
|
2015-02-02 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q)
|
|
|
|
{
|
|
|
|
struct ifa_order_elt *cur, *e1, *e2;
|
2015-02-02 14:37:45 +00:00
|
|
|
unsigned int af1, af2;
|
|
|
|
int ret;
|
2015-02-02 13:03:04 +00:00
|
|
|
|
|
|
|
e1 = e2 = NULL;
|
|
|
|
|
|
|
|
ret = strcmp(a->ifa_name, b->ifa_name);
|
|
|
|
if (ret != 0) {
|
|
|
|
TAILQ_FOREACH(cur, q, link) {
|
|
|
|
if (e1 && e2)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0)
|
|
|
|
e1 = cur;
|
|
|
|
else if (strcmp(cur->ifa->ifa_name, b->ifa_name) == 0)
|
|
|
|
e2 = cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!e1 || !e2)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
return (e1->if_order - e2->if_order);
|
|
|
|
|
|
|
|
} else if (a->ifa_addr != NULL && b->ifa_addr != NULL) {
|
|
|
|
TAILQ_FOREACH(cur, q, link) {
|
|
|
|
if (strcmp(cur->ifa->ifa_name, a->ifa_name) == 0) {
|
|
|
|
e1 = cur;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!e1)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
af1 = a->ifa_addr->sa_family;
|
|
|
|
af2 = b->ifa_addr->sa_family;
|
|
|
|
|
2015-02-02 14:37:45 +00:00
|
|
|
if (af1 < ORDERS_SIZE(e1->af_orders) &&
|
|
|
|
af2 < ORDERS_SIZE(e1->af_orders))
|
2015-02-02 19:00:18 +00:00
|
|
|
return (e1->af_orders[af1] - e1->af_orders[af2]);
|
2015-02-02 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:30:08 +00:00
|
|
|
static void freeformat(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (f_inet != NULL)
|
|
|
|
free(f_inet);
|
|
|
|
if (f_inet6 != NULL)
|
|
|
|
free(f_inet6);
|
|
|
|
if (f_ether != NULL)
|
|
|
|
free(f_ether);
|
|
|
|
if (f_addr != NULL)
|
|
|
|
free(f_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setformat(char *input)
|
|
|
|
{
|
|
|
|
char *formatstr, *category, *modifier;
|
|
|
|
|
|
|
|
formatstr = strdup(input);
|
|
|
|
while ((category = strsep(&formatstr, ",")) != NULL) {
|
|
|
|
modifier = strchr(category, ':');
|
|
|
|
if (modifier == NULL || modifier[1] == '\0') {
|
|
|
|
warnx("Skipping invalid format specification: %s\n",
|
|
|
|
category);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Split the string on the separator, then seek past it */
|
|
|
|
modifier[0] = '\0';
|
|
|
|
modifier++;
|
|
|
|
|
|
|
|
if (strcmp(category, "addr") == 0)
|
|
|
|
f_addr = strdup(modifier);
|
|
|
|
else if (strcmp(category, "ether") == 0)
|
|
|
|
f_ether = strdup(modifier);
|
|
|
|
else if (strcmp(category, "inet") == 0)
|
|
|
|
f_inet = strdup(modifier);
|
|
|
|
else if (strcmp(category, "inet6") == 0)
|
|
|
|
f_inet6 = strdup(modifier);
|
|
|
|
}
|
|
|
|
free(formatstr);
|
|
|
|
}
|
|
|
|
|
2015-02-02 14:37:45 +00:00
|
|
|
#undef ORDERS_SIZE
|
|
|
|
|
2015-02-02 13:03:04 +00:00
|
|
|
static struct ifaddrs *
|
|
|
|
sortifaddrs(struct ifaddrs *list,
|
2015-02-02 14:37:45 +00:00
|
|
|
int (*compare)(struct ifaddrs *, struct ifaddrs *, struct ifa_queue *),
|
|
|
|
struct ifa_queue *q)
|
2015-02-02 13:03:04 +00:00
|
|
|
{
|
|
|
|
struct ifaddrs *right, *temp, *last, *result, *next, *tail;
|
|
|
|
|
|
|
|
right = list;
|
|
|
|
temp = list;
|
|
|
|
last = list;
|
|
|
|
result = NULL;
|
|
|
|
next = NULL;
|
|
|
|
tail = NULL;
|
|
|
|
|
|
|
|
if (!list || !list->ifa_next)
|
|
|
|
return (list);
|
|
|
|
|
|
|
|
while (temp && temp->ifa_next) {
|
|
|
|
last = right;
|
|
|
|
right = right->ifa_next;
|
|
|
|
temp = temp->ifa_next->ifa_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
last->ifa_next = NULL;
|
|
|
|
|
|
|
|
list = sortifaddrs(list, compare, q);
|
|
|
|
right = sortifaddrs(right, compare, q);
|
|
|
|
|
|
|
|
while (list || right) {
|
|
|
|
|
|
|
|
if (!right) {
|
|
|
|
next = list;
|
|
|
|
list = list->ifa_next;
|
|
|
|
} else if (!list) {
|
|
|
|
next = right;
|
|
|
|
right = right->ifa_next;
|
|
|
|
} else if (compare(list, right, q) <= 0) {
|
|
|
|
next = list;
|
|
|
|
list = list->ifa_next;
|
|
|
|
} else {
|
|
|
|
next = right;
|
|
|
|
right = right->ifa_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
result = next;
|
|
|
|
else
|
|
|
|
tail->ifa_next = next;
|
|
|
|
|
|
|
|
tail = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2016-02-20 11:36:35 +00:00
|
|
|
void printifnamemaybe()
|
|
|
|
{
|
|
|
|
if (printifname)
|
|
|
|
printf("%s\n", name);
|
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
int
|
2002-04-18 17:14:09 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
int c, all, namesonly, downonly, uponly;
|
|
|
|
const struct afswtch *afp = NULL;
|
2007-02-24 23:55:46 +00:00
|
|
|
int ifindex;
|
2015-02-02 13:03:04 +00:00
|
|
|
struct ifaddrs *ifap, *sifap, *ifa;
|
2007-02-24 23:55:46 +00:00
|
|
|
struct ifreq paifr;
|
|
|
|
const struct sockaddr_dl *sdl;
|
2016-05-31 17:30:08 +00:00
|
|
|
char options[1024], *cp, *envformat, *namecp = NULL;
|
2015-02-02 13:03:04 +00:00
|
|
|
struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q);
|
|
|
|
struct ifa_order_elt *cur, *tmp;
|
2007-02-24 23:55:46 +00:00
|
|
|
const char *ifname;
|
2004-12-08 19:18:07 +00:00
|
|
|
struct option *p;
|
2007-02-27 17:11:18 +00:00
|
|
|
size_t iflen;
|
2004-12-08 19:18:07 +00:00
|
|
|
|
2007-05-22 17:41:09 +00:00
|
|
|
all = downonly = uponly = namesonly = noload = verbose = 0;
|
2016-06-02 03:16:02 +00:00
|
|
|
f_inet = f_inet6 = f_ether = f_addr = NULL;
|
2016-05-31 17:30:08 +00:00
|
|
|
|
|
|
|
envformat = getenv("IFCONFIG_FORMAT");
|
|
|
|
if (envformat != NULL)
|
|
|
|
setformat(envformat);
|
|
|
|
|
2016-02-20 11:36:35 +00:00
|
|
|
/*
|
|
|
|
* Ensure we print interface name when expected to,
|
|
|
|
* even if we terminate early due to error.
|
|
|
|
*/
|
|
|
|
atexit(printifnamemaybe);
|
1997-05-04 06:14:47 +00:00
|
|
|
|
|
|
|
/* Parse leading line options */
|
2016-05-31 17:30:08 +00:00
|
|
|
strlcpy(options, "f:adklmnuv", sizeof(options));
|
2004-12-08 19:18:07 +00:00
|
|
|
for (p = opts; p != NULL; p = p->next)
|
|
|
|
strlcat(options, p->opt, sizeof(options));
|
|
|
|
while ((c = getopt(argc, argv, options)) != -1) {
|
1997-05-04 06:14:47 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'a': /* scan all interfaces */
|
|
|
|
all++;
|
|
|
|
break;
|
2001-07-02 20:52:34 +00:00
|
|
|
case 'd': /* restrict scan to "down" interfaces */
|
|
|
|
downonly++;
|
1999-12-07 17:39:16 +00:00
|
|
|
break;
|
2016-05-31 17:30:08 +00:00
|
|
|
case 'f':
|
|
|
|
if (optarg == NULL)
|
|
|
|
usage();
|
|
|
|
setformat(optarg);
|
|
|
|
break;
|
2005-07-14 18:33:21 +00:00
|
|
|
case 'k':
|
|
|
|
printkeys++;
|
|
|
|
break;
|
1997-05-04 06:14:47 +00:00
|
|
|
case 'l': /* scan interface names only */
|
|
|
|
namesonly++;
|
|
|
|
break;
|
2001-07-02 20:52:34 +00:00
|
|
|
case 'm': /* show media choices in status */
|
|
|
|
supmedia = 1;
|
1997-05-04 06:14:47 +00:00
|
|
|
break;
|
2007-05-22 17:41:09 +00:00
|
|
|
case 'n': /* suppress module loading */
|
|
|
|
noload++;
|
|
|
|
break;
|
1997-10-27 03:28:44 +00:00
|
|
|
case 'u': /* restrict scan to "up" interfaces */
|
1997-05-04 06:14:47 +00:00
|
|
|
uponly++;
|
|
|
|
break;
|
2004-12-08 19:18:07 +00:00
|
|
|
case 'v':
|
|
|
|
verbose++;
|
1997-05-04 06:27:45 +00:00
|
|
|
break;
|
1997-05-04 06:14:47 +00:00
|
|
|
default:
|
2004-12-08 19:18:07 +00:00
|
|
|
for (p = opts; p != NULL; p = p->next)
|
|
|
|
if (p->opt[0] == c) {
|
|
|
|
p->cb(optarg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p == NULL)
|
|
|
|
usage();
|
1997-05-04 06:14:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* -l cannot be used with -a or -m */
|
2001-05-29 09:13:44 +00:00
|
|
|
if (namesonly && (all || supmedia))
|
1997-05-04 06:14:47 +00:00
|
|
|
usage();
|
|
|
|
|
|
|
|
/* nonsense.. */
|
|
|
|
if (uponly && downonly)
|
|
|
|
usage();
|
|
|
|
|
2000-07-18 22:07:31 +00:00
|
|
|
/* no arguments is equivalent to '-a' */
|
|
|
|
if (!namesonly && argc < 1)
|
|
|
|
all = 1;
|
|
|
|
|
1997-05-04 06:14:47 +00:00
|
|
|
/* -a and -l allow an address family arg to limit the output */
|
|
|
|
if (all || namesonly) {
|
|
|
|
if (argc > 1)
|
|
|
|
usage();
|
|
|
|
|
2007-02-24 23:55:46 +00:00
|
|
|
ifname = NULL;
|
2001-10-17 18:30:13 +00:00
|
|
|
ifindex = 0;
|
1997-05-04 06:14:47 +00:00
|
|
|
if (argc == 1) {
|
2004-12-08 19:18:07 +00:00
|
|
|
afp = af_getbyname(*argv);
|
2011-05-31 14:40:21 +00:00
|
|
|
if (afp == NULL) {
|
|
|
|
warnx("Address family '%s' unknown.", *argv);
|
1997-05-04 06:14:47 +00:00
|
|
|
usage();
|
2011-05-31 14:40:21 +00:00
|
|
|
}
|
2004-12-08 19:18:07 +00:00
|
|
|
if (afp->af_name != NULL)
|
|
|
|
argc--, argv++;
|
1997-05-04 06:14:47 +00:00
|
|
|
/* leave with afp non-zero */
|
|
|
|
}
|
|
|
|
} else {
|
1998-07-06 06:53:43 +00:00
|
|
|
/* not listing, need an argument */
|
1997-05-04 06:14:47 +00:00
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
|
|
|
|
2007-02-24 23:55:46 +00:00
|
|
|
ifname = *argv;
|
1997-05-04 06:14:47 +00:00
|
|
|
argc--, argv++;
|
1999-09-20 07:58:08 +00:00
|
|
|
|
2007-03-24 20:26:54 +00:00
|
|
|
/* check and maybe load support for this interface */
|
|
|
|
ifmaybeload(ifname);
|
|
|
|
|
2007-02-24 23:55:46 +00:00
|
|
|
ifindex = if_nametoindex(ifname);
|
2006-07-09 06:10:23 +00:00
|
|
|
if (ifindex == 0) {
|
|
|
|
/*
|
|
|
|
* NOTE: We must special-case the `create' command
|
|
|
|
* right here as we would otherwise fail when trying
|
|
|
|
* to find the interface.
|
|
|
|
*/
|
|
|
|
if (argc > 0 && (strcmp(argv[0], "create") == 0 ||
|
|
|
|
strcmp(argv[0], "plumb") == 0)) {
|
2007-02-27 17:11:18 +00:00
|
|
|
iflen = strlcpy(name, ifname, sizeof(name));
|
|
|
|
if (iflen >= sizeof(name))
|
|
|
|
errx(1, "%s: cloning name too long",
|
|
|
|
ifname);
|
2008-03-31 15:38:07 +00:00
|
|
|
ifconfig(argc, argv, 1, NULL);
|
2006-07-09 06:10:23 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2012-02-14 07:14:42 +00:00
|
|
|
#ifdef JAIL
|
2009-07-26 11:25:57 +00:00
|
|
|
/*
|
|
|
|
* NOTE: We have to special-case the `-vnet' command
|
|
|
|
* right here as we would otherwise fail when trying
|
|
|
|
* to find the interface as it lives in another vnet.
|
|
|
|
*/
|
|
|
|
if (argc > 0 && (strcmp(argv[0], "-vnet") == 0)) {
|
|
|
|
iflen = strlcpy(name, ifname, sizeof(name));
|
|
|
|
if (iflen >= sizeof(name))
|
|
|
|
errx(1, "%s: interface name too long",
|
|
|
|
ifname);
|
|
|
|
ifconfig(argc, argv, 0, NULL);
|
|
|
|
exit(0);
|
|
|
|
}
|
2012-02-14 07:14:42 +00:00
|
|
|
#endif
|
2007-02-24 23:55:46 +00:00
|
|
|
errx(1, "interface %s does not exist", ifname);
|
2006-07-09 06:10:23 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1997-05-04 06:14:47 +00:00
|
|
|
|
|
|
|
/* Check for address family */
|
1994-05-26 06:35:07 +00:00
|
|
|
if (argc > 0) {
|
2004-12-08 19:18:07 +00:00
|
|
|
afp = af_getbyname(*argv);
|
|
|
|
if (afp != NULL)
|
|
|
|
argc--, argv++;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1996-01-01 09:05:22 +00:00
|
|
|
|
2007-02-24 23:55:46 +00:00
|
|
|
if (getifaddrs(&ifap) != 0)
|
|
|
|
err(EXIT_FAILURE, "getifaddrs");
|
2015-02-02 13:03:04 +00:00
|
|
|
|
2007-02-24 23:55:46 +00:00
|
|
|
cp = NULL;
|
2015-02-02 13:03:04 +00:00
|
|
|
|
|
|
|
if (calcorders(ifap, &q) != 0)
|
|
|
|
err(EXIT_FAILURE, "calcorders");
|
|
|
|
|
|
|
|
sifap = sortifaddrs(ifap, cmpifaddrs, &q);
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(cur, &q, link, tmp)
|
|
|
|
free(cur);
|
|
|
|
|
2007-02-24 23:55:46 +00:00
|
|
|
ifindex = 0;
|
2015-02-02 13:03:04 +00:00
|
|
|
for (ifa = sifap; ifa; ifa = ifa->ifa_next) {
|
2007-02-24 23:55:46 +00:00
|
|
|
memset(&paifr, 0, sizeof(paifr));
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
|
2007-02-24 23:55:46 +00:00
|
|
|
if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) {
|
|
|
|
memcpy(&paifr.ifr_addr, ifa->ifa_addr,
|
|
|
|
ifa->ifa_addr->sa_len);
|
1997-05-10 17:14:53 +00:00
|
|
|
}
|
|
|
|
|
2007-02-24 23:55:46 +00:00
|
|
|
if (ifname != NULL && strcmp(ifname, ifa->ifa_name) != 0)
|
|
|
|
continue;
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_LINK)
|
|
|
|
sdl = (const struct sockaddr_dl *) ifa->ifa_addr;
|
|
|
|
else
|
|
|
|
sdl = NULL;
|
2009-11-25 00:00:57 +00:00
|
|
|
if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0 && !namesonly)
|
2007-02-24 23:55:46 +00:00
|
|
|
continue;
|
2007-02-27 17:11:18 +00:00
|
|
|
iflen = strlcpy(name, ifa->ifa_name, sizeof(name));
|
|
|
|
if (iflen >= sizeof(name)) {
|
|
|
|
warnx("%s: interface name too long, skipping",
|
|
|
|
ifa->ifa_name);
|
2007-02-24 23:55:46 +00:00
|
|
|
continue;
|
2007-02-27 17:11:18 +00:00
|
|
|
}
|
2007-02-24 23:55:46 +00:00
|
|
|
cp = ifa->ifa_name;
|
1997-05-10 17:14:53 +00:00
|
|
|
|
2010-12-07 20:23:47 +00:00
|
|
|
if ((ifa->ifa_flags & IFF_CANTCONFIG) != 0)
|
|
|
|
continue;
|
2007-02-24 23:55:46 +00:00
|
|
|
if (downonly && (ifa->ifa_flags & IFF_UP) != 0)
|
|
|
|
continue;
|
|
|
|
if (uponly && (ifa->ifa_flags & IFF_UP) == 0)
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* Are we just listing the interfaces?
|
|
|
|
*/
|
|
|
|
if (namesonly) {
|
2009-11-25 00:00:57 +00:00
|
|
|
if (namecp == cp)
|
|
|
|
continue;
|
|
|
|
if (afp != NULL) {
|
|
|
|
/* special case for "ether" address family */
|
|
|
|
if (!strcmp(afp->af_name, "ether")) {
|
|
|
|
if (sdl == NULL ||
|
2010-08-06 15:09:21 +00:00
|
|
|
(sdl->sdl_type != IFT_ETHER &&
|
|
|
|
sdl->sdl_type != IFT_L2VLAN &&
|
|
|
|
sdl->sdl_type != IFT_BRIDGE) ||
|
2009-11-25 00:00:57 +00:00
|
|
|
sdl->sdl_alen != ETHER_ADDR_LEN)
|
|
|
|
continue;
|
|
|
|
} else {
|
2015-02-02 14:37:45 +00:00
|
|
|
if (ifa->ifa_addr->sa_family
|
|
|
|
!= afp->af_af)
|
2009-11-25 00:00:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namecp = cp;
|
|
|
|
ifindex++;
|
2007-02-24 23:55:46 +00:00
|
|
|
if (ifindex > 1)
|
|
|
|
printf(" ");
|
|
|
|
fputs(name, stdout);
|
|
|
|
continue;
|
1996-01-01 09:05:22 +00:00
|
|
|
}
|
2009-11-25 00:00:57 +00:00
|
|
|
ifindex++;
|
1996-01-01 09:05:22 +00:00
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
if (argc > 0)
|
2008-03-31 15:38:07 +00:00
|
|
|
ifconfig(argc, argv, 0, afp);
|
1997-05-10 17:14:53 +00:00
|
|
|
else
|
2007-02-24 23:55:46 +00:00
|
|
|
status(afp, sdl, ifa);
|
1996-01-01 09:05:22 +00:00
|
|
|
}
|
2007-02-24 23:55:46 +00:00
|
|
|
if (namesonly)
|
|
|
|
printf("\n");
|
|
|
|
freeifaddrs(ifap);
|
1997-05-04 06:14:47 +00:00
|
|
|
|
2016-05-31 17:30:08 +00:00
|
|
|
freeformat();
|
2007-02-24 23:55:46 +00:00
|
|
|
exit(0);
|
1994-12-30 22:42:41 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static struct afswtch *afs = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
af_register(struct afswtch *p)
|
|
|
|
{
|
|
|
|
p->af_next = afs;
|
|
|
|
afs = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct afswtch *
|
|
|
|
af_getbyname(const char *name)
|
|
|
|
{
|
|
|
|
struct afswtch *afp;
|
|
|
|
|
|
|
|
for (afp = afs; afp != NULL; afp = afp->af_next)
|
|
|
|
if (strcmp(afp->af_name, name) == 0)
|
|
|
|
return afp;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct afswtch *
|
|
|
|
af_getbyfamily(int af)
|
|
|
|
{
|
|
|
|
struct afswtch *afp;
|
|
|
|
|
|
|
|
for (afp = afs; afp != NULL; afp = afp->af_next)
|
|
|
|
if (afp->af_af == af)
|
|
|
|
return afp;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-12-31 19:46:27 +00:00
|
|
|
af_other_status(int s)
|
2004-12-08 19:18:07 +00:00
|
|
|
{
|
|
|
|
struct afswtch *afp;
|
|
|
|
uint8_t afmask[howmany(AF_MAX, NBBY)];
|
|
|
|
|
|
|
|
memset(afmask, 0, sizeof(afmask));
|
|
|
|
for (afp = afs; afp != NULL; afp = afp->af_next) {
|
2004-12-31 19:46:27 +00:00
|
|
|
if (afp->af_other_status == NULL)
|
2004-12-08 19:18:07 +00:00
|
|
|
continue;
|
|
|
|
if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
|
|
|
|
continue;
|
2004-12-31 19:46:27 +00:00
|
|
|
afp->af_other_status(s);
|
2004-12-08 19:18:07 +00:00
|
|
|
setbit(afmask, afp->af_af);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
af_all_tunnel_status(int s)
|
|
|
|
{
|
|
|
|
struct afswtch *afp;
|
|
|
|
uint8_t afmask[howmany(AF_MAX, NBBY)];
|
|
|
|
|
|
|
|
memset(afmask, 0, sizeof(afmask));
|
|
|
|
for (afp = afs; afp != NULL; afp = afp->af_next) {
|
|
|
|
if (afp->af_status_tunnel == NULL)
|
|
|
|
continue;
|
|
|
|
if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
|
|
|
|
continue;
|
|
|
|
afp->af_status_tunnel(s);
|
|
|
|
setbit(afmask, afp->af_af);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cmd *cmds = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
cmd_register(struct cmd *p)
|
|
|
|
{
|
|
|
|
p->c_next = cmds;
|
|
|
|
cmds = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct cmd *
|
2008-09-29 16:27:32 +00:00
|
|
|
cmd_lookup(const char *name, int iscreate)
|
2004-12-08 19:18:07 +00:00
|
|
|
{
|
|
|
|
const struct cmd *p;
|
|
|
|
|
|
|
|
for (p = cmds; p != NULL; p = p->c_next)
|
2008-09-29 16:27:32 +00:00
|
|
|
if (strcmp(name, p->c_name) == 0) {
|
|
|
|
if (iscreate) {
|
|
|
|
if (p->c_iscloneop)
|
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
if (!p->c_iscloneop)
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
2004-12-08 19:18:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-12-11 02:33:33 +00:00
|
|
|
struct callback {
|
|
|
|
callback_func *cb_func;
|
|
|
|
void *cb_arg;
|
|
|
|
struct callback *cb_next;
|
|
|
|
};
|
|
|
|
static struct callback *callbacks = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
callback_register(callback_func *func, void *arg)
|
|
|
|
{
|
|
|
|
struct callback *cb;
|
|
|
|
|
|
|
|
cb = malloc(sizeof(struct callback));
|
|
|
|
if (cb == NULL)
|
|
|
|
errx(1, "unable to allocate memory for callback");
|
|
|
|
cb->cb_func = func;
|
|
|
|
cb->cb_arg = arg;
|
|
|
|
cb->cb_next = callbacks;
|
|
|
|
callbacks = cb;
|
|
|
|
}
|
|
|
|
|
2005-04-08 21:31:20 +00:00
|
|
|
/* specially-handled commands */
|
2004-12-08 19:18:07 +00:00
|
|
|
static void setifaddr(const char *, int, int, const struct afswtch *);
|
|
|
|
static const struct cmd setifaddr_cmd = DEF_CMD("ifaddr", 0, setifaddr);
|
|
|
|
|
|
|
|
static void setifdstaddr(const char *, int, int, const struct afswtch *);
|
|
|
|
static const struct cmd setifdstaddr_cmd =
|
|
|
|
DEF_CMD("ifdstaddr", 0, setifdstaddr);
|
|
|
|
|
|
|
|
static int
|
2009-03-15 22:33:18 +00:00
|
|
|
ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *uafp)
|
1994-12-30 22:42:41 +00:00
|
|
|
{
|
2009-03-15 22:33:18 +00:00
|
|
|
const struct afswtch *afp, *nafp;
|
2008-09-29 16:27:32 +00:00
|
|
|
const struct cmd *p;
|
2004-12-11 02:33:33 +00:00
|
|
|
struct callback *cb;
|
2004-12-08 19:18:07 +00:00
|
|
|
int s;
|
1995-03-12 19:05:03 +00:00
|
|
|
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
|
2011-05-31 14:40:21 +00:00
|
|
|
afp = NULL;
|
|
|
|
if (uafp != NULL)
|
|
|
|
afp = uafp;
|
|
|
|
/*
|
|
|
|
* This is the historical "accident" allowing users to configure IPv4
|
|
|
|
* addresses without the "inet" keyword which while a nice feature has
|
|
|
|
* proven to complicate other things. We cannot remove this but only
|
|
|
|
* make sure we will never have a similar implicit default for IPv6 or
|
|
|
|
* any other address familiy. We need a fallback though for
|
|
|
|
* ifconfig IF up/down etc. to work without INET support as people
|
|
|
|
* never used ifconfig IF link up/down, etc. either.
|
|
|
|
*/
|
2011-07-18 10:29:16 +00:00
|
|
|
#ifndef RESCUE
|
2011-05-31 14:40:21 +00:00
|
|
|
#ifdef INET
|
|
|
|
if (afp == NULL && feature_present("inet"))
|
|
|
|
afp = af_getbyname("inet");
|
2011-07-18 10:29:16 +00:00
|
|
|
#endif
|
2011-05-31 14:40:21 +00:00
|
|
|
#endif
|
|
|
|
if (afp == NULL)
|
|
|
|
afp = af_getbyname("link");
|
|
|
|
if (afp == NULL) {
|
|
|
|
warnx("Please specify an address_family.");
|
|
|
|
usage();
|
|
|
|
}
|
2008-03-31 15:38:07 +00:00
|
|
|
top:
|
2004-12-08 19:18:07 +00:00
|
|
|
ifr.ifr_addr.sa_family =
|
|
|
|
afp->af_af == AF_LINK || afp->af_af == AF_UNSPEC ?
|
2009-03-15 22:33:18 +00:00
|
|
|
AF_LOCAL : afp->af_af;
|
1997-05-04 06:14:47 +00:00
|
|
|
|
2009-03-15 22:33:18 +00:00
|
|
|
if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0 &&
|
2012-12-21 15:54:13 +00:00
|
|
|
(uafp != NULL || errno != EAFNOSUPPORT ||
|
2009-03-15 22:33:18 +00:00
|
|
|
(s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0))
|
2017-08-08 22:40:26 +00:00
|
|
|
err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
|
1996-01-01 09:05:22 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
while (argc > 0) {
|
2008-09-29 16:27:32 +00:00
|
|
|
p = cmd_lookup(*argv, iscreate);
|
|
|
|
if (iscreate && p == NULL) {
|
|
|
|
/*
|
|
|
|
* Push the clone create callback so the new
|
|
|
|
* device is created and can be used for any
|
|
|
|
* remaining arguments.
|
|
|
|
*/
|
|
|
|
cb = callbacks;
|
|
|
|
if (cb == NULL)
|
|
|
|
errx(1, "internal error, no callback");
|
|
|
|
callbacks = cb->cb_next;
|
|
|
|
cb->cb_func(s, cb->cb_arg);
|
|
|
|
iscreate = 0;
|
|
|
|
/*
|
|
|
|
* Handle any address family spec that
|
|
|
|
* immediately follows and potentially
|
|
|
|
* recreate the socket.
|
|
|
|
*/
|
|
|
|
nafp = af_getbyname(*argv);
|
|
|
|
if (nafp != NULL) {
|
|
|
|
argc--, argv++;
|
|
|
|
if (nafp != afp) {
|
|
|
|
close(s);
|
|
|
|
afp = nafp;
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Look for a normal parameter.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
2004-12-08 19:18:07 +00:00
|
|
|
if (p == NULL) {
|
|
|
|
/*
|
|
|
|
* Not a recognized command, choose between setting
|
|
|
|
* the interface address and the dst address.
|
|
|
|
*/
|
|
|
|
p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd);
|
|
|
|
}
|
Various Coverity fixes in ifconfig(8)
* Exit early if kldload(2) fails (1011259). This is the only change that
affects ifconfig's behavior.
* Close memory and resource leaks (1305624, 1305205, 1007100)
* Mark usage() as _Noreturn (1305806, 1305750)
* Fix some dereference after null checks (1011474, 270774)
Reported by: Coverity
CID: 1305624, 1305205, 1007100, 1305806, 1305750, 1011474,
CID: 270774, 1011259
Reviewed by: cem
MFC after: 3 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D10587
2017-05-03 17:21:01 +00:00
|
|
|
if (p->c_parameter == NEXTARG && p->c_u.c_func) {
|
|
|
|
if (argv[1] == NULL)
|
|
|
|
errx(1, "'%s' requires argument",
|
|
|
|
p->c_name);
|
|
|
|
p->c_u.c_func(argv[1], 0, s, afp);
|
|
|
|
argc--, argv++;
|
|
|
|
} else if (p->c_parameter == OPTARG && p->c_u.c_func) {
|
|
|
|
p->c_u.c_func(argv[1], 0, s, afp);
|
|
|
|
if (argv[1] != NULL)
|
1994-05-26 06:35:07 +00:00
|
|
|
argc--, argv++;
|
Various Coverity fixes in ifconfig(8)
* Exit early if kldload(2) fails (1011259). This is the only change that
affects ifconfig's behavior.
* Close memory and resource leaks (1305624, 1305205, 1007100)
* Mark usage() as _Noreturn (1305806, 1305750)
* Fix some dereference after null checks (1011474, 270774)
Reported by: Coverity
CID: 1305624, 1305205, 1007100, 1305806, 1305750, 1011474,
CID: 270774, 1011259
Reviewed by: cem
MFC after: 3 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D10587
2017-05-03 17:21:01 +00:00
|
|
|
} else if (p->c_parameter == NEXTARG2 && p->c_u.c_func2) {
|
|
|
|
if (argc < 3)
|
|
|
|
errx(1, "'%s' requires 2 arguments",
|
|
|
|
p->c_name);
|
|
|
|
p->c_u.c_func2(argv[1], argv[2], s, afp);
|
|
|
|
argc -= 2, argv += 2;
|
|
|
|
} else if (p->c_u.c_func)
|
|
|
|
p->c_u.c_func(*argv, p->c_parameter, s, afp);
|
1994-05-26 06:35:07 +00:00
|
|
|
argc--, argv++;
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
/*
|
|
|
|
* Do any post argument processing required by the address family.
|
|
|
|
*/
|
|
|
|
if (afp->af_postproc != NULL)
|
|
|
|
afp->af_postproc(s, afp);
|
2006-01-30 13:37:34 +00:00
|
|
|
/*
|
|
|
|
* Do deferred callbacks registered while processing
|
|
|
|
* command-line arguments.
|
|
|
|
*/
|
|
|
|
for (cb = callbacks; cb != NULL; cb = cb->cb_next)
|
|
|
|
cb->cb_func(s, cb->cb_arg);
|
2004-12-08 19:18:07 +00:00
|
|
|
/*
|
|
|
|
* Do deferred operations.
|
|
|
|
*/
|
1996-01-08 03:46:27 +00:00
|
|
|
if (clearaddr) {
|
1997-05-10 17:14:53 +00:00
|
|
|
if (afp->af_ridreq == NULL || afp->af_difaddr == 0) {
|
1996-01-08 03:46:27 +00:00
|
|
|
warnx("interface %s cannot change %s addresses!",
|
1997-05-10 17:14:53 +00:00
|
|
|
name, afp->af_name);
|
2004-03-10 08:46:39 +00:00
|
|
|
clearaddr = 0;
|
1996-01-08 03:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
if (clearaddr) {
|
|
|
|
int ret;
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(((struct ifreq *)afp->af_ridreq)->ifr_name, name,
|
|
|
|
sizeof ifr.ifr_name);
|
2004-12-08 19:18:07 +00:00
|
|
|
ret = ioctl(s, afp->af_difaddr, afp->af_ridreq);
|
|
|
|
if (ret < 0) {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
|
|
|
|
/* means no previous address for interface */
|
|
|
|
} else
|
|
|
|
Perror("ioctl (SIOCDIFADDR)");
|
|
|
|
}
|
|
|
|
}
|
1996-01-08 03:46:27 +00:00
|
|
|
if (newaddr) {
|
1999-12-29 13:53:13 +00:00
|
|
|
if (afp->af_addreq == NULL || afp->af_aifaddr == 0) {
|
1996-01-08 03:46:27 +00:00
|
|
|
warnx("interface %s cannot change %s addresses!",
|
1997-05-10 17:14:53 +00:00
|
|
|
name, afp->af_name);
|
1999-12-29 13:53:13 +00:00
|
|
|
newaddr = 0;
|
1996-01-08 03:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-26 16:44:19 +00:00
|
|
|
if (newaddr && (setaddr || setmask)) {
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(((struct ifreq *)afp->af_addreq)->ifr_name, name,
|
|
|
|
sizeof ifr.ifr_name);
|
1997-05-10 17:14:53 +00:00
|
|
|
if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
|
1994-05-26 06:35:07 +00:00
|
|
|
Perror("ioctl (SIOCAIFADDR)");
|
|
|
|
}
|
2004-12-11 02:33:33 +00:00
|
|
|
|
1997-05-04 06:14:47 +00:00
|
|
|
close(s);
|
1994-12-30 22:42:41 +00:00
|
|
|
return(0);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifaddr(const char *addr, int param, int s, const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
if (afp->af_getaddr == NULL)
|
1999-12-29 13:53:13 +00:00
|
|
|
return;
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Delay the ioctl to set the interface addr until flags are all set.
|
|
|
|
* The address interpretation may depend on the flags,
|
|
|
|
* and the flags may change when the address is set.
|
|
|
|
*/
|
|
|
|
setaddr++;
|
2000-07-12 16:41:47 +00:00
|
|
|
if (doalias == 0 && afp->af_af != AF_LINK)
|
1994-05-26 06:35:07 +00:00
|
|
|
clearaddr = 1;
|
2004-12-08 19:18:07 +00:00
|
|
|
afp->af_getaddr(addr, (doalias >= 0 ? ADDR : RIDADDR));
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
settunnel(const char *src, const char *dst, int s, const struct afswtch *afp)
|
2001-06-11 12:39:29 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
struct addrinfo *srcres, *dstres;
|
2001-06-11 12:39:29 +00:00
|
|
|
int ecode;
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
if (afp->af_settunnel == NULL) {
|
|
|
|
warn("address family %s does not support tunnel setup",
|
|
|
|
afp->af_name);
|
|
|
|
return;
|
|
|
|
}
|
2001-06-11 12:39:29 +00:00
|
|
|
|
|
|
|
if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
|
|
|
|
errx(1, "error in parsing address string: %s",
|
|
|
|
gai_strerror(ecode));
|
|
|
|
|
2015-02-02 14:37:45 +00:00
|
|
|
if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
|
2001-06-11 12:39:29 +00:00
|
|
|
errx(1, "error in parsing address string: %s",
|
|
|
|
gai_strerror(ecode));
|
|
|
|
|
|
|
|
if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
|
|
|
|
errx(1,
|
|
|
|
"source and destination address families do not match");
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
afp->af_settunnel(s, srcres, dstres);
|
2001-06-11 12:39:29 +00:00
|
|
|
|
|
|
|
freeaddrinfo(srcres);
|
|
|
|
freeaddrinfo(dstres);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
deletetunnel(const char *vname, int param, int s, const struct afswtch *afp)
|
2001-06-11 12:39:29 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCDIFPHYADDR, &ifr) < 0)
|
|
|
|
err(1, "SIOCDIFPHYADDR");
|
|
|
|
}
|
|
|
|
|
2012-02-14 07:14:42 +00:00
|
|
|
#ifdef JAIL
|
2009-06-24 18:21:37 +00:00
|
|
|
static void
|
|
|
|
setifvnet(const char *jname, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
|
|
|
{
|
|
|
|
struct ifreq my_ifr;
|
|
|
|
|
|
|
|
memcpy(&my_ifr, &ifr, sizeof(my_ifr));
|
2009-07-26 11:25:57 +00:00
|
|
|
my_ifr.ifr_jid = jail_getid(jname);
|
|
|
|
if (my_ifr.ifr_jid < 0)
|
2009-06-24 18:21:37 +00:00
|
|
|
errx(1, "%s", jail_errmsg);
|
2009-07-26 11:25:57 +00:00
|
|
|
if (ioctl(s, SIOCSIFVNET, &my_ifr) < 0)
|
2009-06-24 18:21:37 +00:00
|
|
|
err(1, "SIOCSIFVNET");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setifrvnet(const char *jname, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
|
|
|
{
|
|
|
|
struct ifreq my_ifr;
|
|
|
|
|
|
|
|
memcpy(&my_ifr, &ifr, sizeof(my_ifr));
|
2009-07-26 11:25:57 +00:00
|
|
|
my_ifr.ifr_jid = jail_getid(jname);
|
|
|
|
if (my_ifr.ifr_jid < 0)
|
2009-06-24 18:21:37 +00:00
|
|
|
errx(1, "%s", jail_errmsg);
|
2009-07-26 11:25:57 +00:00
|
|
|
if (ioctl(s, SIOCSIFRVNET, &my_ifr) < 0)
|
|
|
|
err(1, "SIOCSIFRVNET(%d, %s)", my_ifr.ifr_jid, my_ifr.ifr_name);
|
2009-06-24 18:21:37 +00:00
|
|
|
}
|
2012-02-14 07:14:42 +00:00
|
|
|
#endif
|
2009-06-24 18:21:37 +00:00
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifnetmask(const char *addr, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
if (afp->af_getaddr != NULL) {
|
|
|
|
setmask++;
|
|
|
|
afp->af_getaddr(addr, MASK);
|
2002-06-15 15:35:24 +00:00
|
|
|
}
|
|
|
|
}
|
1999-12-07 17:39:16 +00:00
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifbroadaddr(const char *addr, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
if (afp->af_getaddr != NULL)
|
|
|
|
afp->af_getaddr(addr, DSTADDR);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
notealias(const char *addr, int param, int s, const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
#define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr))
|
1994-05-26 06:35:07 +00:00
|
|
|
if (setaddr && doalias == 0 && param < 0)
|
2002-10-02 02:17:59 +00:00
|
|
|
if (afp->af_addreq != NULL && afp->af_ridreq != NULL)
|
|
|
|
bcopy((caddr_t)rqtosa(af_addreq),
|
|
|
|
(caddr_t)rqtosa(af_ridreq),
|
|
|
|
rqtosa(af_addreq)->sa_len);
|
1994-05-26 06:35:07 +00:00
|
|
|
doalias = param;
|
|
|
|
if (param < 0) {
|
|
|
|
clearaddr = 1;
|
|
|
|
newaddr = 0;
|
|
|
|
} else
|
|
|
|
clearaddr = 0;
|
2004-12-08 19:18:07 +00:00
|
|
|
#undef rqtosa
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifdstaddr(const char *addr, int param __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
if (afp->af_getaddr != NULL)
|
|
|
|
afp->af_getaddr(addr, DSTADDR);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
1999-03-15 01:22:01 +00:00
|
|
|
/*
|
|
|
|
* Note: doing an SIOCIGIFFLAGS scribbles on the union portion
|
|
|
|
* of the ifreq structure, which may confuse other parts of ifconfig.
|
|
|
|
* Make a private copy so we can avoid that.
|
|
|
|
*/
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifflags(const char *vname, int value, int s, const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1999-03-15 01:22:01 +00:00
|
|
|
struct ifreq my_ifr;
|
2007-02-24 23:55:46 +00:00
|
|
|
int flags;
|
1999-03-15 01:22:01 +00:00
|
|
|
|
2009-01-14 22:55:49 +00:00
|
|
|
memset(&my_ifr, 0, sizeof(my_ifr));
|
|
|
|
(void) strlcpy(my_ifr.ifr_name, name, sizeof(my_ifr.ifr_name));
|
1999-03-15 01:22:01 +00:00
|
|
|
|
|
|
|
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) {
|
1994-05-26 06:35:07 +00:00
|
|
|
Perror("ioctl (SIOCGIFFLAGS)");
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-08-19 15:16:38 +00:00
|
|
|
flags = (my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16);
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
if (value < 0) {
|
|
|
|
value = -value;
|
|
|
|
flags &= ~value;
|
|
|
|
} else
|
|
|
|
flags |= value;
|
2002-08-18 07:05:00 +00:00
|
|
|
my_ifr.ifr_flags = flags & 0xffff;
|
|
|
|
my_ifr.ifr_flagshigh = flags >> 16;
|
1999-03-15 01:22:01 +00:00
|
|
|
if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0)
|
1994-05-26 06:35:07 +00:00
|
|
|
Perror(vname);
|
|
|
|
}
|
|
|
|
|
2001-09-18 17:43:30 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifcap(const char *vname, int value, int s, const struct afswtch *afp)
|
2001-09-18 17:43:30 +00:00
|
|
|
{
|
2007-02-24 23:55:46 +00:00
|
|
|
int flags;
|
2001-09-18 17:43:30 +00:00
|
|
|
|
|
|
|
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) {
|
|
|
|
Perror("ioctl (SIOCGIFCAP)");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
flags = ifr.ifr_curcap;
|
|
|
|
if (value < 0) {
|
|
|
|
value = -value;
|
|
|
|
flags &= ~value;
|
|
|
|
} else
|
|
|
|
flags |= value;
|
2006-09-20 15:38:37 +00:00
|
|
|
flags &= ifr.ifr_reqcap;
|
2001-09-18 17:43:30 +00:00
|
|
|
ifr.ifr_reqcap = flags;
|
|
|
|
if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0)
|
|
|
|
Perror(vname);
|
|
|
|
}
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifmetric(const char *val, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1994-05-26 06:35:07 +00:00
|
|
|
ifr.ifr_metric = atoi(val);
|
|
|
|
if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)
|
2015-09-16 03:03:19 +00:00
|
|
|
err(1, "ioctl SIOCSIFMETRIC (set metric)");
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifmtu(const char *val, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-08-08 10:45:06 +00:00
|
|
|
{
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1994-08-08 10:45:06 +00:00
|
|
|
ifr.ifr_mtu = atoi(val);
|
|
|
|
if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0)
|
2015-09-16 03:03:19 +00:00
|
|
|
err(1, "ioctl SIOCSIFMTU (set mtu)");
|
1994-08-08 10:45:06 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2004-02-04 02:55:46 +00:00
|
|
|
setifname(const char *val, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
char *newname;
|
2016-02-20 11:36:35 +00:00
|
|
|
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
2004-02-04 02:55:46 +00:00
|
|
|
|
|
|
|
newname = strdup(val);
|
2015-09-16 03:03:19 +00:00
|
|
|
if (newname == NULL)
|
|
|
|
err(1, "no memory to set ifname");
|
2004-02-04 02:55:46 +00:00
|
|
|
ifr.ifr_data = newname;
|
|
|
|
if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
|
|
|
|
free(newname);
|
2015-09-16 03:03:19 +00:00
|
|
|
err(1, "ioctl SIOCSIFNAME (set name)");
|
2004-02-04 02:55:46 +00:00
|
|
|
}
|
2016-02-20 11:36:35 +00:00
|
|
|
printifname = 1;
|
2004-02-04 02:55:46 +00:00
|
|
|
strlcpy(name, newname, sizeof(name));
|
|
|
|
free(newname);
|
|
|
|
}
|
|
|
|
|
2010-01-27 00:30:07 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
static void
|
|
|
|
setifdescr(const char *val, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
|
|
|
{
|
|
|
|
char *newdescr;
|
|
|
|
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
2016-02-20 11:36:35 +00:00
|
|
|
|
2010-01-27 00:30:07 +00:00
|
|
|
ifr.ifr_buffer.length = strlen(val) + 1;
|
|
|
|
if (ifr.ifr_buffer.length == 1) {
|
|
|
|
ifr.ifr_buffer.buffer = newdescr = NULL;
|
|
|
|
ifr.ifr_buffer.length = 0;
|
|
|
|
} else {
|
|
|
|
newdescr = strdup(val);
|
|
|
|
ifr.ifr_buffer.buffer = newdescr;
|
|
|
|
if (newdescr == NULL) {
|
|
|
|
warn("no memory to set ifdescr");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0)
|
2015-09-16 03:03:19 +00:00
|
|
|
err(1, "ioctl SIOCSIFDESCR (set descr)");
|
2010-01-27 00:30:07 +00:00
|
|
|
|
|
|
|
free(newdescr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static void
|
|
|
|
unsetifdescr(const char *val, int value, int s, const struct afswtch *afp)
|
|
|
|
{
|
|
|
|
|
|
|
|
setifdescr("", 0, s, 0);
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#define IFFBITS \
|
2013-11-05 14:11:31 +00:00
|
|
|
"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\7RUNNING" \
|
1996-11-21 19:36:09 +00:00
|
|
|
"\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
|
2009-04-18 20:10:39 +00:00
|
|
|
"\20MULTICAST\22PPROMISC\23MONITOR\24STATICARP"
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2001-09-18 17:43:30 +00:00
|
|
|
#define IFCAPBITS \
|
2006-01-30 14:04:30 +00:00
|
|
|
"\020\1RXCSUM\2TXCSUM\3NETCONS\4VLAN_MTU\5VLAN_HWTAGGING\6JUMBO_MTU\7POLLING" \
|
2008-08-28 22:13:44 +00:00
|
|
|
"\10VLAN_HWCSUM\11TSO4\12TSO6\13LRO\14WOL_UCAST\15WOL_MCAST\16WOL_MAGIC" \
|
2012-06-19 07:34:13 +00:00
|
|
|
"\17TOE4\20TOE6\21VLAN_HWFILTER\23VLAN_HWTSO\24LINKSTATE\25NETMAP" \
|
Implement kernel support for hardware rate limited sockets.
- Add RATELIMIT kernel configuration keyword which must be set to
enable the new functionality.
- Add support for hardware driven, Receive Side Scaling, RSS aware, rate
limited sendqueues and expose the functionality through the already
established SO_MAX_PACING_RATE setsockopt(). The API support rates in
the range from 1 to 4Gbytes/s which are suitable for regular TCP and
UDP streams. The setsockopt(2) manual page has been updated.
- Add rate limit function callback API to "struct ifnet" which supports
the following operations: if_snd_tag_alloc(), if_snd_tag_modify(),
if_snd_tag_query() and if_snd_tag_free().
- Add support to ifconfig to view, set and clear the IFCAP_TXRTLMT
flag, which tells if a network driver supports rate limiting or not.
- This patch also adds support for rate limiting through VLAN and LAGG
intermediate network devices.
- How rate limiting works:
1) The userspace application calls setsockopt() after accepting or
making a new connection to set the rate which is then stored in the
socket structure in the kernel. Later on when packets are transmitted
a check is made in the transmit path for rate changes. A rate change
implies a non-blocking ifp->if_snd_tag_alloc() call will be made to the
destination network interface, which then sets up a custom sendqueue
with the given rate limitation parameter. A "struct m_snd_tag" pointer is
returned which serves as a "snd_tag" hint in the m_pkthdr for the
subsequently transmitted mbufs.
2) When the network driver sees the "m->m_pkthdr.snd_tag" different
from NULL, it will move the packets into a designated rate limited sendqueue
given by the snd_tag pointer. It is up to the individual drivers how the rate
limited traffic will be rate limited.
3) Route changes are detected by the NIC drivers in the ifp->if_transmit()
routine when the ifnet pointer in the incoming snd_tag mismatches the
one of the network interface. The network adapter frees the mbuf and
returns EAGAIN which causes the ip_output() to release and clear the send
tag. Upon next ip_output() a new "snd_tag" will be tried allocated.
4) When the PCB is detached the custom sendqueue will be released by a
non-blocking ifp->if_snd_tag_free() call to the currently bound network
interface.
Reviewed by: wblock (manpages), adrian, gallatin, scottl (network)
Differential Revision: https://reviews.freebsd.org/D3687
Sponsored by: Mellanox Technologies
MFC after: 3 months
2017-01-18 13:31:17 +00:00
|
|
|
"\26RXCSUM_IPV6\27TXCSUM_IPV6\31TXRTLMT"
|
2001-09-18 17:43:30 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Print the status of the interface. If an address family was
|
2004-12-08 19:18:07 +00:00
|
|
|
* specified, show only it; otherwise, show them all.
|
1994-05-26 06:35:07 +00:00
|
|
|
*/
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2007-02-24 23:55:46 +00:00
|
|
|
status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
|
|
|
|
struct ifaddrs *ifa)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2007-02-24 23:55:46 +00:00
|
|
|
struct ifaddrs *ift;
|
1997-05-10 17:14:53 +00:00
|
|
|
int allfamilies, s;
|
1999-06-19 18:42:31 +00:00
|
|
|
struct ifstat ifs;
|
1997-05-10 17:14:53 +00:00
|
|
|
|
|
|
|
if (afp == NULL) {
|
|
|
|
allfamilies = 1;
|
2009-03-15 22:33:18 +00:00
|
|
|
ifr.ifr_addr.sa_family = AF_LOCAL;
|
|
|
|
} else {
|
1997-05-10 17:14:53 +00:00
|
|
|
allfamilies = 0;
|
2009-03-15 22:33:18 +00:00
|
|
|
ifr.ifr_addr.sa_family =
|
|
|
|
afp->af_af == AF_LINK ? AF_LOCAL : afp->af_af;
|
|
|
|
}
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
1997-05-10 17:14:53 +00:00
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0)
|
|
|
|
err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
|
1997-05-10 17:14:53 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
printf("%s: ", name);
|
2007-02-24 23:55:46 +00:00
|
|
|
printb("flags", ifa->ifa_flags, IFFBITS);
|
|
|
|
if (ioctl(s, SIOCGIFMETRIC, &ifr) != -1)
|
|
|
|
printf(" metric %d", ifr.ifr_metric);
|
|
|
|
if (ioctl(s, SIOCGIFMTU, &ifr) != -1)
|
|
|
|
printf(" mtu %d", ifr.ifr_mtu);
|
1994-05-26 06:35:07 +00:00
|
|
|
putchar('\n');
|
1996-01-01 09:05:22 +00:00
|
|
|
|
2010-01-27 00:30:07 +00:00
|
|
|
for (;;) {
|
|
|
|
if ((descr = reallocf(descr, descrlen)) != NULL) {
|
|
|
|
ifr.ifr_buffer.buffer = descr;
|
|
|
|
ifr.ifr_buffer.length = descrlen;
|
|
|
|
if (ioctl(s, SIOCGIFDESCR, &ifr) == 0) {
|
2010-04-14 22:02:19 +00:00
|
|
|
if (ifr.ifr_buffer.buffer == descr) {
|
|
|
|
if (strlen(descr) > 0)
|
|
|
|
printf("\tdescription: %s\n",
|
|
|
|
descr);
|
|
|
|
} else if (ifr.ifr_buffer.length > descrlen) {
|
|
|
|
descrlen = ifr.ifr_buffer.length;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
2010-01-27 00:30:07 +00:00
|
|
|
warn("unable to allocate memory for interface"
|
|
|
|
"description");
|
2010-04-14 22:02:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-01-27 00:30:07 +00:00
|
|
|
|
2001-09-18 17:43:30 +00:00
|
|
|
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) {
|
|
|
|
if (ifr.ifr_curcap != 0) {
|
|
|
|
printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (supmedia && ifr.ifr_reqcap != 0) {
|
2004-12-08 19:18:07 +00:00
|
|
|
printb("\tcapabilities", ifr.ifr_reqcap, IFCAPBITS);
|
2001-09-18 17:43:30 +00:00
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
tunnel_status(s);
|
|
|
|
|
2007-02-24 23:55:46 +00:00
|
|
|
for (ift = ifa; ift != NULL; ift = ift->ifa_next) {
|
|
|
|
if (ift->ifa_addr == NULL)
|
|
|
|
continue;
|
|
|
|
if (strcmp(ifa->ifa_name, ift->ifa_name) != 0)
|
|
|
|
continue;
|
2004-12-08 19:18:07 +00:00
|
|
|
if (allfamilies) {
|
|
|
|
const struct afswtch *p;
|
2007-02-24 23:55:46 +00:00
|
|
|
p = af_getbyfamily(ift->ifa_addr->sa_family);
|
2005-05-20 03:58:53 +00:00
|
|
|
if (p != NULL && p->af_status != NULL)
|
2007-02-24 23:55:46 +00:00
|
|
|
p->af_status(s, ift);
|
|
|
|
} else if (afp->af_af == ift->ifa_addr->sa_family)
|
|
|
|
afp->af_status(s, ift);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2007-02-24 23:55:46 +00:00
|
|
|
#if 0
|
2004-12-31 19:46:27 +00:00
|
|
|
if (allfamilies || afp->af_af == AF_LINK) {
|
|
|
|
const struct afswtch *lafp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hack; the link level address is received separately
|
|
|
|
* from the routing information so any address is not
|
|
|
|
* handled above. Cobble together an entry and invoke
|
|
|
|
* the status method specially.
|
|
|
|
*/
|
|
|
|
lafp = af_getbyname("lladdr");
|
|
|
|
if (lafp != NULL) {
|
|
|
|
info.rti_info[RTAX_IFA] = (struct sockaddr *)sdl;
|
|
|
|
lafp->af_status(s, &info);
|
|
|
|
}
|
|
|
|
}
|
2007-02-24 23:55:46 +00:00
|
|
|
#endif
|
2004-12-08 19:18:07 +00:00
|
|
|
if (allfamilies)
|
2004-12-31 19:46:27 +00:00
|
|
|
af_other_status(s);
|
|
|
|
else if (afp->af_other_status != NULL)
|
|
|
|
afp->af_other_status(s);
|
2004-12-08 19:18:07 +00:00
|
|
|
|
Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated. Additional NUL padding is not required
for short names.
Use sizeof(destination) in a few places instead of IFNAMSIZ.
Cast afp->af_ridreq and afp->af_addreq to make the intent of
the code more obvious.
Reported by: Coverity
CID: 1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID: 1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID: 1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID: 1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID: 1011299, 1305821, 1351720, 1351721
MFC after: 1 week
2016-05-16 00:25:24 +00:00
|
|
|
strlcpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
|
1999-06-19 20:07:24 +00:00
|
|
|
if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0)
|
|
|
|
printf("%s", ifs.ascii);
|
|
|
|
|
2014-08-16 19:13:52 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
sfp_status(s, &ifr, verbose);
|
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
close(s);
|
|
|
|
return;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2002-04-18 17:14:09 +00:00
|
|
|
tunnel_status(int s)
|
2001-06-11 12:39:29 +00:00
|
|
|
{
|
2004-12-08 19:18:07 +00:00
|
|
|
af_all_tunnel_status(s);
|
1994-12-30 22:42:41 +00:00
|
|
|
}
|
1995-05-30 06:12:45 +00:00
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
Perror(const char *cmd)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
switch (errno) {
|
|
|
|
|
|
|
|
case ENXIO:
|
|
|
|
errx(1, "%s: no such interface", cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EPERM:
|
|
|
|
errx(1, "%s: permission denied", cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err(1, "%s", cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print a value a la the %b format of the kernel's printf
|
|
|
|
*/
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
printb(const char *s, unsigned v, const char *bits)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
int i, any = 0;
|
|
|
|
char c;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
if (bits && *bits == 8)
|
|
|
|
printf("%s=%o", s, v);
|
|
|
|
else
|
|
|
|
printf("%s=%x", s, v);
|
|
|
|
if (bits) {
|
Various Coverity fixes in ifconfig(8)
* Exit early if kldload(2) fails (1011259). This is the only change that
affects ifconfig's behavior.
* Close memory and resource leaks (1305624, 1305205, 1007100)
* Mark usage() as _Noreturn (1305806, 1305750)
* Fix some dereference after null checks (1011474, 270774)
Reported by: Coverity
CID: 1305624, 1305205, 1007100, 1305806, 1305750, 1011474,
CID: 270774, 1011259
Reviewed by: cem
MFC after: 3 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D10587
2017-05-03 17:21:01 +00:00
|
|
|
bits++;
|
1994-05-26 06:35:07 +00:00
|
|
|
putchar('<');
|
1996-11-21 19:36:09 +00:00
|
|
|
while ((i = *bits++) != '\0') {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (v & (1 << (i-1))) {
|
|
|
|
if (any)
|
|
|
|
putchar(',');
|
|
|
|
any = 1;
|
|
|
|
for (; (c = *bits) > 32; bits++)
|
|
|
|
putchar(c);
|
|
|
|
} else
|
|
|
|
for (; *bits > 32; bits++)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
putchar('>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
A major overhaul of the CARP implementation. The ip_carp.c was started
from scratch, copying needed functionality from the old implemenation
on demand, with a thorough review of all code. The main change is that
interface layer has been removed from the CARP. Now redundant addresses
are configured exactly on the interfaces, they run on.
The CARP configuration itself is, as before, configured and read via
SIOCSVH/SIOCGVH ioctls. A new prefix created with SIOCAIFADDR or
SIOCAIFADDR_IN6 may now be configured to a particular virtual host id,
which makes the prefix redundant.
ifconfig(8) semantics has been changed too: now one doesn't need
to clone carpXX interface, he/she should directly configure a vhid
on a Ethernet interface.
To supply vhid data from the kernel to an application the getifaddrs(8)
function had been changed to pass ifam_data with each address. [1]
The new implementation definitely closes all PRs related to carp(4)
being an interface, and may close several others. It also allows
to run a single redundant IP per interface.
Big thanks to Bjoern Zeeb for his help with inet6 part of patch, for
idea on using ifam_data and for several rounds of reviewing!
PR: kern/117000, kern/126945, kern/126714, kern/120130, kern/117448
Reviewed by: bz
Submitted by: bz [1]
2011-12-16 12:16:56 +00:00
|
|
|
void
|
|
|
|
print_vhid(const struct ifaddrs *ifa, const char *s)
|
|
|
|
{
|
|
|
|
struct if_data *ifd;
|
|
|
|
|
|
|
|
if (ifa->ifa_data == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ifd = ifa->ifa_data;
|
|
|
|
if (ifd->ifi_vhid == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
printf("vhid %d ", ifd->ifi_vhid);
|
|
|
|
}
|
|
|
|
|
1999-09-20 07:58:08 +00:00
|
|
|
void
|
2007-02-24 23:55:46 +00:00
|
|
|
ifmaybeload(const char *name)
|
1999-09-20 07:58:08 +00:00
|
|
|
{
|
2007-10-04 09:45:41 +00:00
|
|
|
#define MOD_PREFIX_LEN 3 /* "if_" */
|
1999-09-20 07:58:08 +00:00
|
|
|
struct module_stat mstat;
|
|
|
|
int fileid, modid;
|
2007-10-04 09:45:41 +00:00
|
|
|
char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp;
|
2007-02-27 17:03:22 +00:00
|
|
|
const char *cp;
|
1999-09-20 07:58:08 +00:00
|
|
|
|
2007-05-22 17:41:09 +00:00
|
|
|
/* loading suppressed by the user */
|
|
|
|
if (noload)
|
|
|
|
return;
|
|
|
|
|
2007-10-04 09:45:41 +00:00
|
|
|
/* trim the interface number off the end */
|
|
|
|
strlcpy(ifname, name, sizeof(ifname));
|
|
|
|
for (dp = ifname; *dp != 0; dp++)
|
|
|
|
if (isdigit(*dp)) {
|
|
|
|
*dp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-09-20 07:58:08 +00:00
|
|
|
/* turn interface and unit into module name */
|
2015-03-13 09:45:06 +00:00
|
|
|
strlcpy(ifkind, "if_", sizeof(ifkind));
|
|
|
|
strlcat(ifkind, ifname, sizeof(ifkind));
|
1999-09-20 07:58:08 +00:00
|
|
|
|
|
|
|
/* scan files in kernel */
|
|
|
|
mstat.version = sizeof(struct module_stat);
|
|
|
|
for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
|
|
|
|
/* scan modules in file */
|
|
|
|
for (modid = kldfirstmod(fileid); modid > 0;
|
|
|
|
modid = modfnext(modid)) {
|
|
|
|
if (modstat(modid, &mstat) < 0)
|
|
|
|
continue;
|
|
|
|
/* strip bus name if present */
|
|
|
|
if ((cp = strchr(mstat.name, '/')) != NULL) {
|
|
|
|
cp++;
|
|
|
|
} else {
|
|
|
|
cp = mstat.name;
|
|
|
|
}
|
|
|
|
/* already loaded? */
|
2015-03-13 09:45:06 +00:00
|
|
|
if (strcmp(ifname, cp) == 0 ||
|
|
|
|
strcmp(ifkind, cp) == 0)
|
1999-09-20 07:58:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-03 19:53:01 +00:00
|
|
|
/*
|
|
|
|
* Try to load the module. But ignore failures, because ifconfig can't
|
|
|
|
* infer the names of all drivers (eg mlx4en(4)).
|
|
|
|
*/
|
|
|
|
(void) kldload(ifkind);
|
1999-09-20 07:58:08 +00:00
|
|
|
}
|
2001-07-02 20:52:34 +00:00
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static struct cmd basic_cmds[] = {
|
|
|
|
DEF_CMD("up", IFF_UP, setifflags),
|
|
|
|
DEF_CMD("down", -IFF_UP, setifflags),
|
|
|
|
DEF_CMD("arp", -IFF_NOARP, setifflags),
|
|
|
|
DEF_CMD("-arp", IFF_NOARP, setifflags),
|
|
|
|
DEF_CMD("debug", IFF_DEBUG, setifflags),
|
|
|
|
DEF_CMD("-debug", -IFF_DEBUG, setifflags),
|
2010-01-27 00:30:07 +00:00
|
|
|
DEF_CMD_ARG("description", setifdescr),
|
|
|
|
DEF_CMD_ARG("descr", setifdescr),
|
|
|
|
DEF_CMD("-description", 0, unsetifdescr),
|
|
|
|
DEF_CMD("-descr", 0, unsetifdescr),
|
2004-12-08 19:18:07 +00:00
|
|
|
DEF_CMD("promisc", IFF_PPROMISC, setifflags),
|
|
|
|
DEF_CMD("-promisc", -IFF_PPROMISC, setifflags),
|
|
|
|
DEF_CMD("add", IFF_UP, notealias),
|
|
|
|
DEF_CMD("alias", IFF_UP, notealias),
|
|
|
|
DEF_CMD("-alias", -IFF_UP, notealias),
|
|
|
|
DEF_CMD("delete", -IFF_UP, notealias),
|
|
|
|
DEF_CMD("remove", -IFF_UP, notealias),
|
|
|
|
#ifdef notdef
|
|
|
|
#define EN_SWABIPS 0x1000
|
|
|
|
DEF_CMD("swabips", EN_SWABIPS, setifflags),
|
|
|
|
DEF_CMD("-swabips", -EN_SWABIPS, setifflags),
|
|
|
|
#endif
|
|
|
|
DEF_CMD_ARG("netmask", setifnetmask),
|
|
|
|
DEF_CMD_ARG("metric", setifmetric),
|
|
|
|
DEF_CMD_ARG("broadcast", setifbroadaddr),
|
|
|
|
DEF_CMD_ARG2("tunnel", settunnel),
|
2005-09-29 23:53:29 +00:00
|
|
|
DEF_CMD("-tunnel", 0, deletetunnel),
|
2004-12-08 19:18:07 +00:00
|
|
|
DEF_CMD("deletetunnel", 0, deletetunnel),
|
2012-02-14 07:14:42 +00:00
|
|
|
#ifdef JAIL
|
2009-06-24 18:21:37 +00:00
|
|
|
DEF_CMD_ARG("vnet", setifvnet),
|
|
|
|
DEF_CMD_ARG("-vnet", setifrvnet),
|
2012-02-14 07:14:42 +00:00
|
|
|
#endif
|
2004-12-08 19:18:07 +00:00
|
|
|
DEF_CMD("link0", IFF_LINK0, setifflags),
|
|
|
|
DEF_CMD("-link0", -IFF_LINK0, setifflags),
|
|
|
|
DEF_CMD("link1", IFF_LINK1, setifflags),
|
|
|
|
DEF_CMD("-link1", -IFF_LINK1, setifflags),
|
|
|
|
DEF_CMD("link2", IFF_LINK2, setifflags),
|
|
|
|
DEF_CMD("-link2", -IFF_LINK2, setifflags),
|
|
|
|
DEF_CMD("monitor", IFF_MONITOR, setifflags),
|
|
|
|
DEF_CMD("-monitor", -IFF_MONITOR, setifflags),
|
|
|
|
DEF_CMD("staticarp", IFF_STATICARP, setifflags),
|
|
|
|
DEF_CMD("-staticarp", -IFF_STATICARP, setifflags),
|
It turns out that too many drivers are not only parsing the L2/3/4
headers for TSO but also for generic checksum offloading. Ideally we
would only have one common function shared amongst all drivers, and
perhaps when updating them for IPv6 we should introduce that.
Eventually we should provide the meta information along with mbufs to
avoid (re-)parsing entirely.
To not break IPv6 (checksums and offload) and to be able to MFC the
changes without risking to hurt 3rd party drivers, duplicate the v4
framework, as other OSes have done as well.
Introduce interface capability flags for TX/RX checksum offload with
IPv6, to allow independent toggling (where possible). Add CSUM_*_IPV6
flags for UDP/TCP over IPv6, and reserve further for SCTP, and IPv6
fragmentation. Define CSUM_DELAY_DATA_IPV6 as we do for legacy IP and
add an alias for CSUM_DATA_VALID_IPV6.
This pretty much brings IPv6 handling in line with IPv4.
TSO is still handled in a different way and not via if_hwassist.
Update ifconfig to allow (un)setting of the new capability flags.
Update loopback to announce the new capabilities and if_hwassist flags.
Individual driver updates will have to follow, as will SCTP.
Reported by: gallatin, dim, ..
Reviewed by: gallatin (glanced at?)
MFC after: 3 days
X-MFC with: r235961,235959,235958
2012-05-28 09:30:13 +00:00
|
|
|
DEF_CMD("rxcsum6", IFCAP_RXCSUM_IPV6, setifcap),
|
|
|
|
DEF_CMD("-rxcsum6", -IFCAP_RXCSUM_IPV6, setifcap),
|
|
|
|
DEF_CMD("txcsum6", IFCAP_TXCSUM_IPV6, setifcap),
|
|
|
|
DEF_CMD("-txcsum6", -IFCAP_TXCSUM_IPV6, setifcap),
|
2004-12-08 19:18:07 +00:00
|
|
|
DEF_CMD("rxcsum", IFCAP_RXCSUM, setifcap),
|
|
|
|
DEF_CMD("-rxcsum", -IFCAP_RXCSUM, setifcap),
|
|
|
|
DEF_CMD("txcsum", IFCAP_TXCSUM, setifcap),
|
|
|
|
DEF_CMD("-txcsum", -IFCAP_TXCSUM, setifcap),
|
|
|
|
DEF_CMD("netcons", IFCAP_NETCONS, setifcap),
|
|
|
|
DEF_CMD("-netcons", -IFCAP_NETCONS, setifcap),
|
|
|
|
DEF_CMD("polling", IFCAP_POLLING, setifcap),
|
|
|
|
DEF_CMD("-polling", -IFCAP_POLLING, setifcap),
|
2012-05-19 23:25:57 +00:00
|
|
|
DEF_CMD("tso6", IFCAP_TSO6, setifcap),
|
|
|
|
DEF_CMD("-tso6", -IFCAP_TSO6, setifcap),
|
|
|
|
DEF_CMD("tso4", IFCAP_TSO4, setifcap),
|
|
|
|
DEF_CMD("-tso4", -IFCAP_TSO4, setifcap),
|
2006-09-06 22:07:14 +00:00
|
|
|
DEF_CMD("tso", IFCAP_TSO, setifcap),
|
|
|
|
DEF_CMD("-tso", -IFCAP_TSO, setifcap),
|
2012-06-19 07:34:13 +00:00
|
|
|
DEF_CMD("toe", IFCAP_TOE, setifcap),
|
|
|
|
DEF_CMD("-toe", -IFCAP_TOE, setifcap),
|
2007-06-11 20:15:20 +00:00
|
|
|
DEF_CMD("lro", IFCAP_LRO, setifcap),
|
|
|
|
DEF_CMD("-lro", -IFCAP_LRO, setifcap),
|
2007-12-10 02:31:00 +00:00
|
|
|
DEF_CMD("wol", IFCAP_WOL, setifcap),
|
|
|
|
DEF_CMD("-wol", -IFCAP_WOL, setifcap),
|
|
|
|
DEF_CMD("wol_ucast", IFCAP_WOL_UCAST, setifcap),
|
|
|
|
DEF_CMD("-wol_ucast", -IFCAP_WOL_UCAST, setifcap),
|
|
|
|
DEF_CMD("wol_mcast", IFCAP_WOL_MCAST, setifcap),
|
|
|
|
DEF_CMD("-wol_mcast", -IFCAP_WOL_MCAST, setifcap),
|
|
|
|
DEF_CMD("wol_magic", IFCAP_WOL_MAGIC, setifcap),
|
|
|
|
DEF_CMD("-wol_magic", -IFCAP_WOL_MAGIC, setifcap),
|
Implement kernel support for hardware rate limited sockets.
- Add RATELIMIT kernel configuration keyword which must be set to
enable the new functionality.
- Add support for hardware driven, Receive Side Scaling, RSS aware, rate
limited sendqueues and expose the functionality through the already
established SO_MAX_PACING_RATE setsockopt(). The API support rates in
the range from 1 to 4Gbytes/s which are suitable for regular TCP and
UDP streams. The setsockopt(2) manual page has been updated.
- Add rate limit function callback API to "struct ifnet" which supports
the following operations: if_snd_tag_alloc(), if_snd_tag_modify(),
if_snd_tag_query() and if_snd_tag_free().
- Add support to ifconfig to view, set and clear the IFCAP_TXRTLMT
flag, which tells if a network driver supports rate limiting or not.
- This patch also adds support for rate limiting through VLAN and LAGG
intermediate network devices.
- How rate limiting works:
1) The userspace application calls setsockopt() after accepting or
making a new connection to set the rate which is then stored in the
socket structure in the kernel. Later on when packets are transmitted
a check is made in the transmit path for rate changes. A rate change
implies a non-blocking ifp->if_snd_tag_alloc() call will be made to the
destination network interface, which then sets up a custom sendqueue
with the given rate limitation parameter. A "struct m_snd_tag" pointer is
returned which serves as a "snd_tag" hint in the m_pkthdr for the
subsequently transmitted mbufs.
2) When the network driver sees the "m->m_pkthdr.snd_tag" different
from NULL, it will move the packets into a designated rate limited sendqueue
given by the snd_tag pointer. It is up to the individual drivers how the rate
limited traffic will be rate limited.
3) Route changes are detected by the NIC drivers in the ifp->if_transmit()
routine when the ifnet pointer in the incoming snd_tag mismatches the
one of the network interface. The network adapter frees the mbuf and
returns EAGAIN which causes the ip_output() to release and clear the send
tag. Upon next ip_output() a new "snd_tag" will be tried allocated.
4) When the PCB is detached the custom sendqueue will be released by a
non-blocking ifp->if_snd_tag_free() call to the currently bound network
interface.
Reviewed by: wblock (manpages), adrian, gallatin, scottl (network)
Differential Revision: https://reviews.freebsd.org/D3687
Sponsored by: Mellanox Technologies
MFC after: 3 months
2017-01-18 13:31:17 +00:00
|
|
|
DEF_CMD("txrtlmt", IFCAP_TXRTLMT, setifcap),
|
|
|
|
DEF_CMD("-txrtlmt", -IFCAP_TXRTLMT, setifcap),
|
2004-12-08 19:18:07 +00:00
|
|
|
DEF_CMD("normal", -IFF_LINK0, setifflags),
|
|
|
|
DEF_CMD("compress", IFF_LINK0, setifflags),
|
|
|
|
DEF_CMD("noicmp", IFF_LINK1, setifflags),
|
|
|
|
DEF_CMD_ARG("mtu", setifmtu),
|
|
|
|
DEF_CMD_ARG("name", setifname),
|
|
|
|
};
|
2001-07-02 20:52:34 +00:00
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static __constructor void
|
|
|
|
ifconfig_ctor(void)
|
2001-07-02 20:52:34 +00:00
|
|
|
{
|
2009-06-23 23:49:52 +00:00
|
|
|
size_t i;
|
2001-07-02 20:52:34 +00:00
|
|
|
|
2015-09-27 07:51:18 +00:00
|
|
|
for (i = 0; i < nitems(basic_cmds); i++)
|
2004-12-08 19:18:07 +00:00
|
|
|
cmd_register(&basic_cmds[i]);
|
2001-07-02 20:52:34 +00:00
|
|
|
}
|