summaryrefslogtreecommitdiffstats
path: root/freebsd/sbin
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-12-09 14:19:03 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-01-10 09:53:34 +0100
commit75b706fde4cbf82bcd41a1cec319778aa0f8eb2d (patch)
treeea39a351a1f6337b5a5dd6036314693adef5ffe6 /freebsd/sbin
parentVMSTAT(8): Port to RTEMS (diff)
downloadrtems-libbsd-75b706fde4cbf82bcd41a1cec319778aa0f8eb2d.tar.bz2
Update to FreeBSD head 2016-12-10
Git mirror commit 80c55f08a05ab3b26a73b226ccb56adc3122a55c.
Diffstat (limited to 'freebsd/sbin')
-rw-r--r--freebsd/sbin/dhclient/clparse.c2
-rw-r--r--freebsd/sbin/dhclient/dhclient.c15
-rw-r--r--freebsd/sbin/dhclient/dhcpd.h2
-rw-r--r--freebsd/sbin/dhclient/dispatch.c48
-rw-r--r--freebsd/sbin/dhclient/privsep.c8
-rw-r--r--freebsd/sbin/dhclient/privsep.h3
-rw-r--r--freebsd/sbin/dhclient/tables.c1
-rw-r--r--freebsd/sbin/ifconfig/af_inet.c2
-rw-r--r--freebsd/sbin/ifconfig/af_inet6.c2
-rw-r--r--freebsd/sbin/ifconfig/af_link.c25
-rw-r--r--freebsd/sbin/pfctl/parse.y78
-rw-r--r--freebsd/sbin/pfctl/pfctl.c2
-rw-r--r--freebsd/sbin/pfctl/pfctl_optimize.c4
-rw-r--r--freebsd/sbin/pfctl/pfctl_parser.c8
-rw-r--r--freebsd/sbin/sysctl/sysctl.c3
15 files changed, 168 insertions, 35 deletions
diff --git a/freebsd/sbin/dhclient/clparse.c b/freebsd/sbin/dhclient/clparse.c
index a65236fc..10df53b3 100644
--- a/freebsd/sbin/dhclient/clparse.c
+++ b/freebsd/sbin/dhclient/clparse.c
@@ -104,6 +104,8 @@ read_client_conf(void)
[top_level_config.requested_option_count++] = DHO_HOST_NAME;
top_level_config.requested_options
[top_level_config.requested_option_count++] = DHO_DOMAIN_SEARCH;
+ top_level_config.requested_options
+ [top_level_config.requested_option_count++] = DHO_INTERFACE_MTU;
if ((cfile = fopen(path_dhclient_conf, "r")) != NULL) {
do {
diff --git a/freebsd/sbin/dhclient/dhclient.c b/freebsd/sbin/dhclient/dhclient.c
index c7b75c59..46ffaffc 100644
--- a/freebsd/sbin/dhclient/dhclient.c
+++ b/freebsd/sbin/dhclient/dhclient.c
@@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
#include "privsep.h"
#include <sys/capsicum.h>
+#include <sys/endian.h>
#include <net80211/ieee80211_freebsd.h>
@@ -134,6 +135,9 @@ int fork_privchld(int, int);
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
+/* Minimum MTU is 68 as per RFC791, p. 24 */
+#define MIN_MTU 68
+
static time_t scripttime;
int
@@ -800,9 +804,20 @@ dhcpack(struct packet *packet)
void
bind_lease(struct interface_info *ip)
{
+ struct option_data *opt;
+
/* Remember the medium. */
ip->client->new->medium = ip->client->medium;
+ opt = &ip->client->new->options[DHO_INTERFACE_MTU];
+ if (opt->len == sizeof(u_int16_t)) {
+ u_int16_t mtu = be16dec(opt->data);
+ if (mtu < MIN_MTU)
+ warning("mtu size %u < %d: ignored", (unsigned)mtu, MIN_MTU);
+ else
+ interface_set_mtu_unpriv(privfd, mtu);
+ }
+
/* Write out the new lease. */
write_client_lease(ip, ip->client->new, 0);
diff --git a/freebsd/sbin/dhclient/dhcpd.h b/freebsd/sbin/dhclient/dhcpd.h
index 852513a8..f2bc7738 100644
--- a/freebsd/sbin/dhclient/dhcpd.h
+++ b/freebsd/sbin/dhclient/dhcpd.h
@@ -319,6 +319,8 @@ void cancel_timeout(void (*)(void *), void *);
void add_protocol(char *, int, void (*)(struct protocol *), void *);
void remove_protocol(struct protocol *);
int interface_link_status(char *);
+void interface_set_mtu_unpriv(int, u_int16_t);
+void interface_set_mtu_priv(char *, u_int16_t);
/* hash.c */
struct hash_table *new_hash(void);
diff --git a/freebsd/sbin/dhclient/dispatch.c b/freebsd/sbin/dhclient/dispatch.c
index 4a68c62d..d37c9925 100644
--- a/freebsd/sbin/dhclient/dispatch.c
+++ b/freebsd/sbin/dhclient/dispatch.c
@@ -45,6 +45,7 @@
__FBSDID("$FreeBSD$");
#include "dhcpd.h"
+#include "privsep.h"
#include <sys/ioctl.h>
@@ -107,8 +108,8 @@ discover_interfaces(struct interface_info *iface)
if (foo.sin_addr.s_addr == htonl(INADDR_LOOPBACK))
continue;
if (!iface->ifp) {
- int len = IFNAMSIZ + ifa->ifa_addr->sa_len;
- if ((tif = malloc(len)) == NULL)
+ if ((tif = calloc(1, sizeof(struct ifreq)))
+ == NULL)
error("no space to remember ifp");
strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ);
memcpy(&tif->ifr_addr, ifa->ifa_addr,
@@ -503,3 +504,46 @@ interface_link_status(char *ifname)
}
return (1);
}
+
+void
+interface_set_mtu_unpriv(int privfd, u_int16_t mtu)
+{
+ struct imsg_hdr hdr;
+ struct buf *buf;
+ int errs = 0;
+
+ hdr.code = IMSG_SET_INTERFACE_MTU;
+ hdr.len = sizeof(hdr) +
+ sizeof(u_int16_t);
+
+ if ((buf = buf_open(hdr.len)) == NULL)
+ error("buf_open: %m");
+
+ errs += buf_add(buf, &hdr, sizeof(hdr));
+ errs += buf_add(buf, &mtu, sizeof(mtu));
+ if (errs)
+ error("buf_add: %m");
+
+ if (buf_close(privfd, buf) == -1)
+ error("buf_close: %m");
+}
+
+void
+interface_set_mtu_priv(char *ifname, u_int16_t mtu)
+{
+ struct ifreq ifr;
+ int sock;
+
+ if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+ error("Can't create socket");
+
+ memset(&ifr, 0, sizeof(ifr));
+
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ ifr.ifr_mtu = mtu;
+
+ if (ioctl(sock, SIOCSIFMTU, &ifr) == -1)
+ warning("SIOCSIFMTU failed (%d): %s", mtu,
+ strerror(errno));
+ close(sock);
+}
diff --git a/freebsd/sbin/dhclient/privsep.c b/freebsd/sbin/dhclient/privsep.c
index aa1042fd..b1cf5106 100644
--- a/freebsd/sbin/dhclient/privsep.c
+++ b/freebsd/sbin/dhclient/privsep.c
@@ -113,6 +113,7 @@ dispatch_imsg(struct interface_info *ifi, int fd)
struct client_lease lease;
int ret, i, optlen;
struct buf *buf;
+ u_int16_t mtu;
buf_read(fd, &hdr, sizeof(hdr));
@@ -237,6 +238,13 @@ dispatch_imsg(struct interface_info *ifi, int fd)
case IMSG_SEND_PACKET:
send_packet_priv(ifi, &hdr, fd);
break;
+ case IMSG_SET_INTERFACE_MTU:
+ if (hdr.len < sizeof(hdr) + sizeof(u_int16_t))
+ error("corrupted message received");
+
+ buf_read(fd, &mtu, sizeof(u_int16_t));
+ interface_set_mtu_priv(ifi->name, mtu);
+ break;
default:
error("received unknown message, code %d", hdr.code);
}
diff --git a/freebsd/sbin/dhclient/privsep.h b/freebsd/sbin/dhclient/privsep.h
index d464da43..e1a7338f 100644
--- a/freebsd/sbin/dhclient/privsep.h
+++ b/freebsd/sbin/dhclient/privsep.h
@@ -36,7 +36,8 @@ enum imsg_code {
IMSG_SCRIPT_WRITE_PARAMS,
IMSG_SCRIPT_GO,
IMSG_SCRIPT_GO_RET,
- IMSG_SEND_PACKET
+ IMSG_SEND_PACKET,
+ IMSG_SET_INTERFACE_MTU,
};
struct imsg_hdr {
diff --git a/freebsd/sbin/dhclient/tables.c b/freebsd/sbin/dhclient/tables.c
index d73022d1..6339898c 100644
--- a/freebsd/sbin/dhclient/tables.c
+++ b/freebsd/sbin/dhclient/tables.c
@@ -402,6 +402,7 @@ unsigned char dhcp_option_default_priority_list[] = {
DHO_IRC_SERVER,
DHO_STREETTALK_SERVER,
DHO_STREETTALK_DA_SERVER,
+ DHO_DHCP_USER_CLASS_ID,
DHO_DOMAIN_SEARCH,
/* Presently-undefined options... */
diff --git a/freebsd/sbin/ifconfig/af_inet.c b/freebsd/sbin/ifconfig/af_inet.c
index d464df52..040da216 100644
--- a/freebsd/sbin/ifconfig/af_inet.c
+++ b/freebsd/sbin/ifconfig/af_inet.c
@@ -100,7 +100,7 @@ in_status(int s __unused, const struct ifaddrs *ifa)
sin = (struct sockaddr_in *)ifa->ifa_dstaddr;
if (sin == NULL)
sin = &null_sin;
- printf(" --> %s ", inet_ntoa(sin->sin_addr));
+ printf(" --> %s", inet_ntoa(sin->sin_addr));
}
sin = (struct sockaddr_in *)ifa->ifa_netmask;
diff --git a/freebsd/sbin/ifconfig/af_inet6.c b/freebsd/sbin/ifconfig/af_inet6.c
index f743ee8f..d3d58ade 100644
--- a/freebsd/sbin/ifconfig/af_inet6.c
+++ b/freebsd/sbin/ifconfig/af_inet6.c
@@ -250,7 +250,7 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
if (error != 0)
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
sizeof(addr_buf));
- printf(" --> %s ", addr_buf);
+ printf(" --> %s", addr_buf);
}
}
diff --git a/freebsd/sbin/ifconfig/af_link.c b/freebsd/sbin/ifconfig/af_link.c
index 1c37496e..5fa2545d 100644
--- a/freebsd/sbin/ifconfig/af_link.c
+++ b/freebsd/sbin/ifconfig/af_link.c
@@ -102,13 +102,24 @@ link_getaddr(const char *addr, int which)
if (which != ADDR)
errx(1, "can't set link-level netmask or broadcast");
- if ((temp = malloc(strlen(addr) + 2)) == NULL)
- errx(1, "malloc failed");
- temp[0] = ':';
- strcpy(temp + 1, addr);
- sdl.sdl_len = sizeof(sdl);
- link_addr(temp, &sdl);
- free(temp);
+ if (!strcmp(addr, "random")) {
+ sdl.sdl_len = sizeof(sdl);
+ sdl.sdl_alen = ETHER_ADDR_LEN;
+ sdl.sdl_nlen = 0;
+ sdl.sdl_family = AF_LINK;
+ arc4random_buf(&sdl.sdl_data, ETHER_ADDR_LEN);
+ /* Non-multicast and claim it is locally administered. */
+ sdl.sdl_data[0] &= 0xfc;
+ sdl.sdl_data[0] |= 0x02;
+ } else {
+ if ((temp = malloc(strlen(addr) + 2)) == NULL)
+ errx(1, "malloc failed");
+ temp[0] = ':';
+ strcpy(temp + 1, addr);
+ sdl.sdl_len = sizeof(sdl);
+ link_addr(temp, &sdl);
+ free(temp);
+ }
if (sdl.sdl_alen > sizeof(sa->sa_data))
errx(1, "malformed link-level address");
sa->sa_family = AF_LINK;
diff --git a/freebsd/sbin/pfctl/parse.y b/freebsd/sbin/pfctl/parse.y
index 33edd3e5..9664aaf5 100644
--- a/freebsd/sbin/pfctl/parse.y
+++ b/freebsd/sbin/pfctl/parse.y
@@ -367,6 +367,8 @@ void decide_address_family(struct node_host *, sa_family_t *);
void remove_invalid_hosts(struct node_host **, sa_family_t *);
int invalid_redirect(struct node_host *, sa_family_t);
u_int16_t parseicmpspec(char *, sa_family_t);
+int kw_casecmp(const void *, const void *);
+int map_tos(char *string, int *);
static TAILQ_HEAD(loadanchorshead, loadanchors)
loadanchorshead = TAILQ_HEAD_INITIALIZER(loadanchorshead);
@@ -2346,7 +2348,7 @@ pfrule : action dir logquick interface route af proto fromto
memcpy(&r.rpool.key, $5.key,
sizeof(struct pf_poolhashkey));
}
- if (r.rt && r.rt != PF_FASTROUTE) {
+ if (r.rt) {
decide_address_family($5.host, &r.af);
remove_invalid_hosts(&$5.host, &r.af);
if ($5.host == NULL) {
@@ -3600,15 +3602,17 @@ icmp6type : STRING {
;
tos : STRING {
- if (!strcmp($1, "lowdelay"))
- $$ = IPTOS_LOWDELAY;
- else if (!strcmp($1, "throughput"))
- $$ = IPTOS_THROUGHPUT;
- else if (!strcmp($1, "reliability"))
- $$ = IPTOS_RELIABILITY;
- else if ($1[0] == '0' && $1[1] == 'x')
- $$ = strtoul($1, NULL, 16);
- else
+ int val;
+ char *end;
+
+ if (map_tos($1, &val))
+ $$ = val;
+ else if ($1[0] == '0' && $1[1] == 'x') {
+ errno = 0;
+ $$ = strtoul($1, &end, 16);
+ if (errno || *end != '\0')
+ $$ = 256;
+ } else
$$ = 256; /* flag bad argument */
if ($$ < 0 || $$ > 255) {
yyerror("illegal tos value %s", $1);
@@ -4432,8 +4436,9 @@ route : /* empty */ {
$$.pool_opts = 0;
}
| FASTROUTE {
+ /* backwards-compat */
$$.host = NULL;
- $$.rt = PF_FASTROUTE;
+ $$.rt = 0;
$$.pool_opts = 0;
}
| ROUTETO routespec pool_opts {
@@ -6270,6 +6275,57 @@ pfctl_load_anchors(int dev, struct pfctl *pf, struct pfr_buffer *trans)
}
int
+kw_casecmp(const void *k, const void *e)
+{
+ return (strcasecmp(k, ((const struct keywords *)e)->k_name));
+}
+
+int
+map_tos(char *s, int *val)
+{
+ /* DiffServ Codepoints and other TOS mappings */
+ const struct keywords toswords[] = {
+ { "af11", IPTOS_DSCP_AF11 },
+ { "af12", IPTOS_DSCP_AF12 },
+ { "af13", IPTOS_DSCP_AF13 },
+ { "af21", IPTOS_DSCP_AF21 },
+ { "af22", IPTOS_DSCP_AF22 },
+ { "af23", IPTOS_DSCP_AF23 },
+ { "af31", IPTOS_DSCP_AF31 },
+ { "af32", IPTOS_DSCP_AF32 },
+ { "af33", IPTOS_DSCP_AF33 },
+ { "af41", IPTOS_DSCP_AF41 },
+ { "af42", IPTOS_DSCP_AF42 },
+ { "af43", IPTOS_DSCP_AF43 },
+ { "critical", IPTOS_PREC_CRITIC_ECP },
+ { "cs0", IPTOS_DSCP_CS0 },
+ { "cs1", IPTOS_DSCP_CS1 },
+ { "cs2", IPTOS_DSCP_CS2 },
+ { "cs3", IPTOS_DSCP_CS3 },
+ { "cs4", IPTOS_DSCP_CS4 },
+ { "cs5", IPTOS_DSCP_CS5 },
+ { "cs6", IPTOS_DSCP_CS6 },
+ { "cs7", IPTOS_DSCP_CS7 },
+ { "ef", IPTOS_DSCP_EF },
+ { "inetcontrol", IPTOS_PREC_INTERNETCONTROL },
+ { "lowdelay", IPTOS_LOWDELAY },
+ { "netcontrol", IPTOS_PREC_NETCONTROL },
+ { "reliability", IPTOS_RELIABILITY },
+ { "throughput", IPTOS_THROUGHPUT }
+ };
+ const struct keywords *p;
+
+ p = bsearch(s, toswords, sizeof(toswords)/sizeof(toswords[0]),
+ sizeof(toswords[0]), kw_casecmp);
+
+ if (p) {
+ *val = p->k_val;
+ return (1);
+ }
+ return (0);
+}
+
+int
rt_tableid_max(void)
{
#ifdef __FreeBSD__
diff --git a/freebsd/sbin/pfctl/pfctl.c b/freebsd/sbin/pfctl/pfctl.c
index ab597068..f9efa090 100644
--- a/freebsd/sbin/pfctl/pfctl.c
+++ b/freebsd/sbin/pfctl/pfctl.c
@@ -1364,7 +1364,7 @@ pfctl_load_rule(struct pfctl *pf, char *path, struct pf_rule *r, int depth)
else
snprintf(&path[len], MAXPATHLEN - len,
"%s", r->anchor->name);
- name = path;
+ name = r->anchor->name;
} else
name = r->anchor->path;
} else
diff --git a/freebsd/sbin/pfctl/pfctl_optimize.c b/freebsd/sbin/pfctl/pfctl_optimize.c
index b8f44e8b..89cebe91 100644
--- a/freebsd/sbin/pfctl/pfctl_optimize.c
+++ b/freebsd/sbin/pfctl/pfctl_optimize.c
@@ -103,7 +103,7 @@ TAILQ_HEAD(superblocks, superblock);
* Description of the PF rule structure.
*/
enum {
- BARRIER, /* the presence of the field puts the rule in it's own block */
+ BARRIER, /* the presence of the field puts the rule in its own block */
BREAK, /* the field may not differ between rules in a superblock */
NOMERGE, /* the field may not differ between rules when combined */
COMBINED, /* the field may itself be combined with other rules */
@@ -127,7 +127,7 @@ static struct pf_rule_field pf_rule_desc[] = {
/*
- * The presence of these fields in a rule put the rule in it's own
+ * The presence of these fields in a rule put the rule in its own
* superblock. Thus it will not be optimized. It also prevents the
* rule from being re-ordered at all.
*/
diff --git a/freebsd/sbin/pfctl/pfctl_parser.c b/freebsd/sbin/pfctl/pfctl_parser.c
index 0ff7deec..cb49dc2a 100644
--- a/freebsd/sbin/pfctl/pfctl_parser.c
+++ b/freebsd/sbin/pfctl/pfctl_parser.c
@@ -790,12 +790,8 @@ print_rule(struct pf_rule *r, const char *anchor_call, int verbose, int numeric)
printf(" reply-to");
else if (r->rt == PF_DUPTO)
printf(" dup-to");
- else if (r->rt == PF_FASTROUTE)
- printf(" fastroute");
- if (r->rt != PF_FASTROUTE) {
- printf(" ");
- print_pool(&r->rpool, 0, 0, r->af, PF_PASS);
- }
+ printf(" ");
+ print_pool(&r->rpool, 0, 0, r->af, PF_PASS);
}
if (r->af) {
if (r->af == AF_INET)
diff --git a/freebsd/sbin/sysctl/sysctl.c b/freebsd/sbin/sysctl/sysctl.c
index fdbecd5f..03069a38 100644
--- a/freebsd/sbin/sysctl/sysctl.c
+++ b/freebsd/sbin/sysctl/sysctl.c
@@ -677,9 +677,6 @@ S_vmtotal(size_t l2, void *p)
}
#ifdef __amd64__
-#define efi_next_descriptor(ptr, size) \
- ((struct efi_md *)(((uint8_t *) ptr) + size))
-
static int
S_efi_map(size_t l2, void *p)
{