summaryrefslogtreecommitdiffstats
path: root/sys/net
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>1999-03-24 21:20:12 +0000
committerdes <des@FreeBSD.org>1999-03-24 21:20:12 +0000
commitc42abfb1fe46d89d8c6bffc17aa69c778f17e2b4 (patch)
treec4fb14cf123bef01355ac24ff5ed246251c8e011 /sys/net
parent16fa182f0f1cc1f668faf444396a1c821dd7291e (diff)
downloadFreeBSD-src-c42abfb1fe46d89d8c6bffc17aa69c778f17e2b4.zip
FreeBSD-src-c42abfb1fe46d89d8c6bffc17aa69c778f17e2b4.tar.gz
Implement TUNSIFMODE and TUNSLMODE.
Submitted by: Alfred Perlstein <bright@cygnus.rush.net>
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if_tun.c43
-rw-r--r--sys/net/if_tun.h4
-rw-r--r--sys/net/if_tunvar.h3
3 files changed, 47 insertions, 3 deletions
diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c
index c395ee3..e9725bc 100644
--- a/sys/net/if_tun.c
+++ b/sys/net/if_tun.c
@@ -338,7 +338,24 @@ tunoutput(ifp, m0, dst, rt)
bpf_mtap(ifp, &m);
}
-#endif
+#endif /* NBPFILTER > 0 */
+
+ /* prepend sockaddr? this may abort if the mbuf allocation fails */
+ if (tp->tun_flags & TUN_LMODE) {
+ /* allocate space for sockaddr */
+ M_PREPEND(m0, dst->sa_len, M_DONTWAIT);
+
+ /* if allocation failed drop packet */
+ if (m0 == NULL){
+ s = splimp(); /* spl on queue manipulation */
+ IF_DROP(&ifp->if_snd);
+ splx(s);
+ ifp->if_oerrors++;
+ return (ENOBUFS);
+ } else {
+ bcopy(dst, m0->m_data, dst->sa_len);
+ }
+ }
switch(dst->sa_family) {
#ifdef INET
@@ -406,6 +423,30 @@ tunioctl(dev, cmd, data, flag, p)
case TUNGDEBUG:
*(int *)data = tundebug;
break;
+ case TUNSLMODE:
+ if (*(int *)data)
+ tp->tun_flags |= TUN_LMODE;
+ else
+ tp->tun_flags &= ~TUN_LMODE;
+ break;
+ case TUNSIFMODE:
+ /* deny this if UP */
+ if (tp->tun_if.if_flags & IFF_UP)
+ return(EBUSY);
+
+ switch (*(int *)data) {
+ case IFF_POINTOPOINT:
+ tp->tun_if.if_flags |= IFF_POINTOPOINT;
+ tp->tun_if.if_flags &= ~IFF_BROADCAST;
+ break;
+ case IFF_BROADCAST:
+ tp->tun_if.if_flags &= ~IFF_POINTOPOINT;
+ tp->tun_if.if_flags |= IFF_BROADCAST;
+ break;
+ default:
+ return(EINVAL);
+ }
+ break;
case FIONBIO:
break;
case FIOASYNC:
diff --git a/sys/net/if_tun.h b/sys/net/if_tun.h
index 3173085..1a1fa64 100644
--- a/sys/net/if_tun.h
+++ b/sys/net/if_tun.h
@@ -13,7 +13,7 @@
* UCL. This driver is based much more on read/write/select mode of
* operation though.
*
- * $Id: if_tun.h,v 1.12 1998/01/26 19:52:34 brian Exp $
+ * $Id: if_tun.h,v 1.13 1998/04/17 22:36:56 des Exp $
*/
#ifndef _NET_IF_TUN_H_
@@ -39,5 +39,7 @@ struct tuninfo {
#define TUNGDEBUG _IOR('t', 89, int)
#define TUNSIFINFO _IOW('t', 91, struct tuninfo)
#define TUNGIFINFO _IOR('t', 92, struct tuninfo)
+#define TUNSLMODE _IOW('t', 93, int)
+#define TUNSIFMODE _IOW('t', 94, int)
#endif /* !_NET_IF_TUN_H_ */
diff --git a/sys/net/if_tunvar.h b/sys/net/if_tunvar.h
index 9e537d3..496c4fb 100644
--- a/sys/net/if_tunvar.h
+++ b/sys/net/if_tunvar.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: if_tunvar.h,v 1.2 1998/11/11 10:04:10 truckman Exp $
+ * $Id: if_tunvar.h,v 1.3 1998/11/11 10:56:05 truckman Exp $
*/
#ifndef _NET_IF_TUNVAR_H_
@@ -36,6 +36,7 @@ struct tun_softc {
#define TUN_RCOLL 0x0004
#define TUN_IASET 0x0008
#define TUN_DSTADDR 0x0010
+#define TUN_LMODE 0x0020
#define TUN_RWAIT 0x0040
#define TUN_ASYNC 0x0080
OpenPOWER on IntegriCloud