Define IF_MAXMTU and IF_MINMTU and don't allow MTUs with

out-of-range values.

``comparison is always 0'' warnings are silly !

Ok'd by:	wollman, dg
Advised by:	bde
This commit is contained in:
Brian Somers 1999-08-06 13:53:03 +00:00
parent 2e4e1ffe62
commit aab3beeede
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=49459
5 changed files with 31 additions and 15 deletions

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)if.c 8.3 (Berkeley) 1/4/94
* $Id: if.c,v 1.72 1999/06/06 09:28:01 phk Exp $
* $Id: if.c,v 1.73 1999/06/19 18:42:26 phk Exp $
*/
#include "opt_compat.h"
@ -685,11 +685,7 @@ ifioctl(so, cmd, data, p)
return (error);
if (ifp->if_ioctl == NULL)
return (EOPNOTSUPP);
/*
* 72 was chosen below because it is the size of a TCP/IP
* header (40) + the minimum mss (32).
*/
if (ifr->ifr_mtu < 72 || ifr->ifr_mtu > 65535)
if (ifr->ifr_mtu < IF_MINMTU || ifr->ifr_mtu > IF_MAXMTU)
return (EINVAL);
error = (*ifp->if_ioctl)(ifp, cmd, data);
if (error == 0)

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)if_loop.c 8.1 (Berkeley) 6/10/93
* $Id: if_loop.c,v 1.38 1999/02/20 21:03:53 dt Exp $
* $Id: if_loop.c,v 1.39 1999/07/06 19:23:13 des Exp $
*/
/*
@ -346,7 +346,10 @@ loioctl(ifp, cmd, data)
break;
case SIOCSIFMTU:
ifp->if_mtu = ifr->ifr_mtu;
if (ifr->ifr_mtu < IF_MINMTU || ifr->ifr_mtu > IF_MAXMTU)
error = EINVAL;
else
ifp->if_mtu = ifr->ifr_mtu;
break;
case SIOCSIFFLAGS:

View File

@ -69,7 +69,7 @@
* Paul Mackerras (paulus@cs.anu.edu.au).
*/
/* $Id: if_ppp.c,v 1.60 1999/04/27 11:17:00 phk Exp $ */
/* $Id: if_ppp.c,v 1.61 1999/07/06 19:23:13 des Exp $ */
/* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
@ -618,9 +618,13 @@ pppsioctl(ifp, cmd, data)
if (ifr->ifr_mtu > PPP_MAXMTU)
error = EINVAL;
else {
sc->sc_if.if_mtu = ifr->ifr_mtu;
if (sc->sc_setmtu)
if (ifr->ifr_mtu < IF_MINMTU || ifr->ifr_mtu > IF_MAXMTU)
error = EINVAL;
else {
sc->sc_if.if_mtu = ifr->ifr_mtu;
if (sc->sc_setmtu)
(*sc->sc_setmtu)(sc);
}
}
break;

View File

@ -302,9 +302,12 @@ tunifioctl(ifp, cmd, data)
ifp->if_name, ifp->if_unit);
break;
case SIOCSIFMTU:
ifp->if_mtu = ifr->ifr_mtu;
TUNDEBUG("%s%d: mtu set\n",
ifp->if_name, ifp->if_unit);
if (ifr->ifr_mtu < IF_MINMTU || ifr->ifr_mtu > IF_MAXMTU)
error = EINVAL;
else {
ifp->if_mtu = ifr->ifr_mtu;
TUNDEBUG("%s%d: mtu set\n", ifp->if_name, ifp->if_unit);
}
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
@ -435,6 +438,8 @@ tunioctl(dev, cmd, data, flag, p)
switch (cmd) {
case TUNSIFINFO:
tunp = (struct tuninfo *)data;
if (tunp->mtu < IF_MINMTU || tunp->mtu > IF_MAXMTU)
return (EINVAL);
tp->tun_if.if_mtu = tunp->mtu;
tp->tun_if.if_type = tunp->type;
tp->tun_if.if_baudrate = tunp->baudrate;

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* From: @(#)if.h 8.1 (Berkeley) 6/10/93
* $Id: if_var.h,v 1.12 1999/05/06 18:12:55 peter Exp $
* $Id: if_var.h,v 1.13 1999/05/16 17:09:20 pb Exp $
*/
#ifndef _NET_IF_VAR_H_
@ -231,6 +231,14 @@ int if_enq_drop __P((struct ifqueue *, struct mbuf *));
#endif
#endif
/*
* 72 was chosen below because it is the size of a TCP/IP
* header (40) + the minimum mss (32).
*/
#define IF_MINMTU 72
#define IF_MAXMTU 65535
#endif /* KERNEL */
/*