diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2002-12-07 19:12:35 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2002-12-07 19:12:35 +0000 |
commit | f799b5fa73a85d905541af837a1c0e3caf673a04 (patch) | |
tree | ffec42ac2df38ae5d5cb6b9ed5da7b0cdcbad355 /sbin | |
parent | 394872c73472f2f01411207cdc84e39c5e0cd74f (diff) |
get the interface's MTU instead of assuming 1500
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/pfctl/pfctl_altq.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/sbin/pfctl/pfctl_altq.c b/sbin/pfctl/pfctl_altq.c index 5c17f9d681a..d1b62daadd5 100644 --- a/sbin/pfctl/pfctl_altq.c +++ b/sbin/pfctl/pfctl_altq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_altq.c,v 1.18 2002/12/06 16:16:15 henning Exp $ */ +/* $OpenBSD: pfctl_altq.c,v 1.19 2002/12/07 19:12:34 henning Exp $ */ /* * Copyright (C) 2002 @@ -55,6 +55,7 @@ static int check_commit_cbq(int, int, struct pf_altq *); static void print_cbq_opts(const struct pf_altq *); static char *rate2str(double); u_int32_t getifspeed(char *); +u_long getifmtu(char *); TAILQ_HEAD(altqs, pf_altq) altqs = TAILQ_HEAD_INITIALIZER(altqs); @@ -211,7 +212,7 @@ eval_pfaltq(struct pfctl *pf, struct pf_altq *pa, u_int32_t bw_absolute, size = 8; else size = 24; - size = size * 1500; /* assume the default mtu is 1500 */ + size = size * getifmtu(pa->ifname); pa->tbrsize = size; } return (errors); @@ -298,9 +299,7 @@ eval_pfqueue_cbq(struct pfctl *pf, struct pf_altq *pa) struct cbq_opts *opts; u_int ifmtu; -#if 1 - ifmtu = 1500; /* should be obtained from the interface */ -#endif + ifmtu = getifmtu(pa->ifname); opts = &pa->pq_u.cbq_opts; if (opts->pktsize == 0) { /* use default */ @@ -632,3 +631,24 @@ getifspeed(char *ifname) err(1, "shutdown"); return ((u_int32_t)ifrdat.ifi_baudrate); } + +u_long +getifmtu(char *ifname) +{ + int s; + struct ifreq ifr; + + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + err(1, "socket"); + strlcpy(ifr.ifr_name, ifname, IFNAMSIZ); + if (ioctl(s, SIOCGIFMTU, (caddr_t)&ifr) == -1) + err(1, "SIOCGIFMTU"); + if (shutdown(s, SHUT_RDWR) == -1) + err(1, "shutdown"); + if (ifr.ifr_mtu > 0) + return (ifr.ifr_mtu); + else { + warnx("could not get mtu for %s, assuming 1500", ifname); + return (1500); + } +} |