2006-04-23 04:13:19 +04:00
|
|
|
/* $NetBSD: ns_ip.c,v 1.41 2006/04/23 00:13:19 christos Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
1994-05-13 10:10:16 +04:00
|
|
|
* Copyright (c) 1984, 1985, 1986, 1987, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-04-09 16:00:07 +04: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.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)ns_ip.c 8.2 (Berkeley) 1/9/95
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Software interface driver for encapsulating ns in ip.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 03:56:55 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-04-23 04:13:19 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ns_ip.c,v 1.41 2006/04/23 00:13:19 christos Exp $");
|
2001-11-13 03:56:55 +03:00
|
|
|
|
1999-10-25 23:18:10 +04:00
|
|
|
#include "opt_ns.h" /* options NSIP, needed by ns_if.h */
|
1998-07-05 10:49:00 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/protosw.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-10-11 03:22:58 +04:00
|
|
|
#include <machine/stdarg.h>
|
1996-05-10 02:29:25 +04:00
|
|
|
#include <machine/cpu.h> /* XXX for setsoftnet(). This must die. */
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <net/route.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
1996-10-11 03:22:58 +04:00
|
|
|
#include <netns/ns_var.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netns/idp.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
struct ifnet_en {
|
|
|
|
struct ifnet ifen_ifnet;
|
|
|
|
struct route ifen_route;
|
|
|
|
struct in_addr ifen_src;
|
|
|
|
struct in_addr ifen_dst;
|
|
|
|
struct ifnet_en *ifen_next;
|
|
|
|
};
|
|
|
|
|
2004-04-19 04:10:48 +04:00
|
|
|
int nsipoutput (struct ifnet *, struct mbuf *m, struct sockaddr *,
|
|
|
|
struct rtentry *);
|
|
|
|
int nsipioctl (struct ifnet *, u_long, caddr_t);
|
|
|
|
void nsipstart (struct ifnet *);
|
|
|
|
int nsip_route (struct mbuf *);
|
|
|
|
void nsip_rtchange (struct in_addr *);
|
1993-04-09 16:00:07 +04:00
|
|
|
#define LOMTU (1024+512);
|
|
|
|
|
1996-05-07 06:40:22 +04:00
|
|
|
int nsipif_unit; /* XXX */
|
1993-04-09 16:00:07 +04:00
|
|
|
struct ifnet nsipif;
|
|
|
|
struct ifnet_en *nsip_list; /* list of all hosts and gateways or
|
|
|
|
broadcast addrs */
|
|
|
|
|
|
|
|
struct ifnet_en *
|
2004-04-19 04:10:48 +04:00
|
|
|
nsipattach(void)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifnet_en *m;
|
|
|
|
struct ifnet *ifp;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (nsipif.if_mtu == 0) {
|
|
|
|
ifp = &nsipif;
|
2004-04-21 22:40:37 +04:00
|
|
|
snprintf(ifp->if_xname, sizeof(ifp->if_xname), "nsip%d",
|
|
|
|
nsipif_unit);
|
1993-04-09 16:00:07 +04:00
|
|
|
ifp->if_mtu = LOMTU;
|
|
|
|
ifp->if_ioctl = nsipioctl;
|
|
|
|
ifp->if_output = nsipoutput;
|
|
|
|
ifp->if_start = nsipstart;
|
|
|
|
ifp->if_flags = IFF_POINTOPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
MALLOC((m), struct ifnet_en *, sizeof(*m), M_PCB, M_NOWAIT);
|
|
|
|
if (m == NULL) return (NULL);
|
|
|
|
m->ifen_next = nsip_list;
|
|
|
|
nsip_list = m;
|
|
|
|
ifp = &m->ifen_ifnet;
|
|
|
|
|
2004-04-21 22:40:37 +04:00
|
|
|
snprintf(ifp->if_xname, sizeof(ifp->if_xname), "nsip%d", nsipif_unit++);
|
1993-04-09 16:00:07 +04:00
|
|
|
ifp->if_mtu = LOMTU;
|
|
|
|
ifp->if_ioctl = nsipioctl;
|
|
|
|
ifp->if_output = nsipoutput;
|
|
|
|
ifp->if_start = nsipstart;
|
|
|
|
ifp->if_flags = IFF_POINTOPOINT;
|
|
|
|
if_attach(ifp);
|
2001-01-17 03:30:49 +03:00
|
|
|
if_alloc_sadl(ifp);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-05-07 06:40:22 +04:00
|
|
|
/*
|
|
|
|
* XXX Emulate the side effect of incrementing nsipif.if_unit
|
|
|
|
* XXX in the days before if_xname.
|
|
|
|
*/
|
1996-10-11 03:22:58 +04:00
|
|
|
bzero(nsipif.if_xname, sizeof(nsipif.if_xname));
|
2004-04-21 22:40:37 +04:00
|
|
|
snprintf(nsipif.if_xname, sizeof(nsipif.if_xname), "nsip%d",
|
|
|
|
nsipif_unit);
|
1996-05-07 06:40:22 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
1996-10-11 03:22:58 +04:00
|
|
|
int
|
2004-04-19 04:10:48 +04:00
|
|
|
nsipioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
struct ifreq *ifr;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
/* fall into: */
|
|
|
|
|
2004-04-19 04:10:48 +04:00
|
|
|
/*FALLTHROUGH*/
|
1993-04-09 16:00:07 +04:00
|
|
|
case SIOCSIFDSTADDR:
|
|
|
|
/*
|
|
|
|
* Everything else is done at a higher level.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
ifr = (struct ifreq *)data;
|
|
|
|
if ((ifr->ifr_flags & IFF_UP) == 0)
|
|
|
|
error = nsip_free(ifp);
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mbuf *nsip_badlen;
|
|
|
|
struct mbuf *nsip_lastin;
|
|
|
|
int nsip_hold_input;
|
|
|
|
|
1996-10-11 03:22:58 +04:00
|
|
|
void
|
|
|
|
idpip_input(struct mbuf *m, ...)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-10-11 03:22:58 +04:00
|
|
|
struct ifnet *ifp;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ip *ip;
|
|
|
|
struct idp *idp;
|
|
|
|
struct ifqueue *ifq = &nsintrq;
|
1993-04-09 16:00:07 +04:00
|
|
|
int len, s;
|
1996-10-11 03:22:58 +04:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, m);
|
|
|
|
ifp = va_arg(ap, struct ifnet *);
|
|
|
|
va_end(ap);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (nsip_hold_input) {
|
|
|
|
if (nsip_lastin) {
|
|
|
|
m_freem(nsip_lastin);
|
|
|
|
}
|
|
|
|
nsip_lastin = m_copym(m, 0, (int)M_COPYALL, M_DONTWAIT);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Get IP and IDP header together in first mbuf.
|
|
|
|
*/
|
|
|
|
nsipif.if_ipackets++;
|
|
|
|
s = sizeof (struct ip) + sizeof (struct idp);
|
|
|
|
if (((m->m_flags & M_EXT) || m->m_len < s) &&
|
|
|
|
(m = m_pullup(m, s)) == 0) {
|
|
|
|
nsipif.if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
if (ip->ip_hl > (sizeof (struct ip) >> 2)) {
|
1994-05-13 10:10:16 +04:00
|
|
|
ip_stripoptions(m, (struct mbuf *)0);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (m->m_len < s) {
|
|
|
|
if ((m = m_pullup(m, s)) == 0) {
|
|
|
|
nsipif.if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make mbuf data length reflect IDP length.
|
|
|
|
* If not enough data to reflect IDP length, drop.
|
|
|
|
*/
|
|
|
|
m->m_data += sizeof (struct ip);
|
|
|
|
m->m_len -= sizeof (struct ip);
|
|
|
|
m->m_pkthdr.len -= sizeof (struct ip);
|
|
|
|
idp = mtod(m, struct idp *);
|
|
|
|
len = ntohs(idp->idp_len);
|
|
|
|
if (len & 1) len++; /* Preserve Garbage Byte */
|
2003-06-27 01:59:42 +04:00
|
|
|
if (ntohs(ip->ip_len) - (ip->ip_hl << 2) != len) {
|
|
|
|
if (len > ntohs(ip->ip_len) - (ip->ip_hl << 2)) {
|
1993-04-09 16:00:07 +04:00
|
|
|
nsipif.if_ierrors++;
|
|
|
|
if (nsip_badlen) m_freem(nsip_badlen);
|
|
|
|
nsip_badlen = m;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Any extra will be trimmed off by the NS routines */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place interface pointer before the data
|
|
|
|
* for the receiving protocol.
|
|
|
|
*/
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
/*
|
|
|
|
* Deliver to NS
|
|
|
|
*/
|
2001-04-14 03:29:55 +04:00
|
|
|
s = splnet();
|
1993-04-09 16:00:07 +04:00
|
|
|
if (IF_QFULL(ifq)) {
|
|
|
|
IF_DROP(ifq);
|
|
|
|
m_freem(m);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IF_ENQUEUE(ifq, m);
|
|
|
|
schednetisr(NETISR_NS);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1996-10-11 03:22:58 +04:00
|
|
|
int
|
2004-04-19 04:10:48 +04:00
|
|
|
nsipoutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
|
|
|
|
struct rtentry *rt)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-10-11 03:22:58 +04:00
|
|
|
struct ifnet_en *ifn = (struct ifnet_en *) ifp;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ip *ip;
|
|
|
|
struct route *ro = &(ifn->ifen_route);
|
|
|
|
int len = 0;
|
|
|
|
struct idp *idp = mtod(m, struct idp *);
|
1993-04-09 16:00:07 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
ifn->ifen_ifnet.if_opackets++;
|
|
|
|
nsipif.if_opackets++;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate data length and make space
|
|
|
|
* for IP header.
|
|
|
|
*/
|
1997-07-18 23:30:33 +04:00
|
|
|
len = ntohs(idp->idp_len);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (len & 1) len++; /* Preserve Garbage Byte */
|
2006-04-23 04:13:19 +04:00
|
|
|
if (!ALIGNED_POINTER(m->m_data, m->m_data)) {
|
1993-04-09 16:00:07 +04:00
|
|
|
/* force longword alignment of ip hdr */
|
1994-01-07 02:58:17 +03:00
|
|
|
struct mbuf *m0 = m_gethdr(M_DONTWAIT, MT_HEADER);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (m0 == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
MH_ALIGN(m0, sizeof (struct ip));
|
|
|
|
m0->m_flags = m->m_flags & M_COPYFLAGS;
|
|
|
|
m0->m_next = m;
|
|
|
|
m0->m_len = sizeof (struct ip);
|
|
|
|
m0->m_pkthdr.len = m0->m_len + m->m_len;
|
2003-10-04 00:57:29 +04:00
|
|
|
m_tag_delete_chain(m, NULL);
|
1993-04-09 16:00:07 +04:00
|
|
|
m->m_flags &= ~M_PKTHDR;
|
|
|
|
} else {
|
|
|
|
M_PREPEND(m, sizeof (struct ip), M_DONTWAIT);
|
|
|
|
if (m == 0)
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Fill in IP header.
|
|
|
|
*/
|
|
|
|
ip = mtod(m, struct ip *);
|
1997-07-18 23:30:33 +04:00
|
|
|
*(int32_t *)ip = 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
ip->ip_p = IPPROTO_IDP;
|
|
|
|
ip->ip_src = ifn->ifen_src;
|
|
|
|
ip->ip_dst = ifn->ifen_dst;
|
2002-08-14 04:23:27 +04:00
|
|
|
if (len + sizeof (struct ip) > IP_MAXPACKET) {
|
|
|
|
m_freem(m);
|
|
|
|
return (EMSGSIZE);
|
|
|
|
}
|
|
|
|
ip->ip_len = htons(len + sizeof (struct ip));
|
1993-04-09 16:00:07 +04:00
|
|
|
ip->ip_ttl = MAXTTL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output final datagram.
|
|
|
|
*/
|
2003-08-15 07:42:00 +04:00
|
|
|
error = ip_output(m, (struct mbuf *)0, ro, SO_BROADCAST,
|
2003-08-23 01:53:01 +04:00
|
|
|
(struct ip_moptions *)NULL, (struct socket *)NULL);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (error) {
|
|
|
|
ifn->ifen_ifnet.if_oerrors++;
|
|
|
|
ifn->ifen_ifnet.if_ierrors = error;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-04-11 08:25:21 +04:00
|
|
|
void
|
2004-04-19 04:10:48 +04:00
|
|
|
nsipstart(struct ifnet *ifp)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("nsip_start called");
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
1996-05-07 06:40:22 +04:00
|
|
|
struct ifreq ifr = {"nsip0"}; /* XXX */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-10-11 03:22:58 +04:00
|
|
|
int
|
2004-04-19 04:10:48 +04:00
|
|
|
nsip_route(struct mbuf *m)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nsip_req *rq = mtod(m, struct nsip_req *);
|
1995-06-13 12:36:58 +04:00
|
|
|
struct sockaddr_ns *ns_dst = satosns(&rq->rq_ns);
|
|
|
|
struct sockaddr_in *ip_dst = satosin(&rq->rq_ip);
|
1993-04-09 16:00:07 +04:00
|
|
|
struct route ro;
|
|
|
|
struct ifnet_en *ifn;
|
|
|
|
struct sockaddr_in *src;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, make sure we already have an ns address:
|
|
|
|
*/
|
|
|
|
if (ns_hosteqnh(ns_thishost, ns_zerohost))
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
/*
|
|
|
|
* Now, determine if we can get to the destination
|
|
|
|
*/
|
|
|
|
bzero((caddr_t)&ro, sizeof (ro));
|
1995-06-13 12:36:58 +04:00
|
|
|
ro.ro_dst = *sintosa(ip_dst);
|
1993-04-09 16:00:07 +04:00
|
|
|
rtalloc(&ro);
|
|
|
|
if (ro.ro_rt == 0 || ro.ro_rt->rt_ifp == 0) {
|
|
|
|
return (ENETUNREACH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* And see how he's going to get back to us:
|
|
|
|
* i.e., what return ip address do we use?
|
|
|
|
*/
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct in_ifaddr *ia;
|
1993-04-09 16:00:07 +04:00
|
|
|
struct ifnet *ifp = ro.ro_rt->rt_ifp;
|
|
|
|
|
2003-11-14 18:04:48 +03:00
|
|
|
for (ia = in_ifaddrhead.tqh_first; ia != 0;
|
1995-06-13 12:36:58 +04:00
|
|
|
ia = ia->ia_list.tqe_next)
|
1993-04-09 16:00:07 +04:00
|
|
|
if (ia->ia_ifp == ifp)
|
|
|
|
break;
|
|
|
|
if (ia == 0)
|
2003-11-14 18:04:48 +03:00
|
|
|
ia = in_ifaddrhead.tqh_first;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (ia == 0) {
|
|
|
|
RTFREE(ro.ro_rt);
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
1995-06-13 12:36:58 +04:00
|
|
|
src = satosin(&ia->ia_addr);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is there a free (pseudo-)interface or space?
|
|
|
|
*/
|
|
|
|
for (ifn = nsip_list; ifn; ifn = ifn->ifen_next) {
|
|
|
|
if ((ifn->ifen_ifnet.if_flags & IFF_UP) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ifn == NULL)
|
|
|
|
ifn = nsipattach();
|
|
|
|
if (ifn == NULL) {
|
|
|
|
RTFREE(ro.ro_rt);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
ifn->ifen_route = ro;
|
|
|
|
ifn->ifen_dst = ip_dst->sin_addr;
|
|
|
|
ifn->ifen_src = src->sin_addr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now configure this as a point to point link
|
|
|
|
*/
|
1996-05-07 06:40:22 +04:00
|
|
|
bzero(ifr.ifr_name, sizeof(ifr.ifr_name));
|
2004-04-21 22:40:37 +04:00
|
|
|
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "nsip%d", nsipif_unit - 1);
|
1995-06-13 12:36:58 +04:00
|
|
|
ifr.ifr_dstaddr = *snstosa(ns_dst);
|
1995-03-08 05:14:50 +03:00
|
|
|
(void)ns_control((struct socket *)0, SIOCSIFDSTADDR, (caddr_t)&ifr,
|
1996-10-11 03:22:58 +04:00
|
|
|
(struct ifnet *)ifn, NULL);
|
1993-04-09 16:00:07 +04:00
|
|
|
satons_addr(ifr.ifr_addr).x_host = ns_thishost;
|
1995-03-08 05:14:50 +03:00
|
|
|
return (ns_control((struct socket *)0, SIOCSIFADDR, (caddr_t)&ifr,
|
1996-10-11 03:22:58 +04:00
|
|
|
(struct ifnet *)ifn, NULL));
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
1996-02-14 01:13:43 +03:00
|
|
|
int
|
2004-04-19 04:10:48 +04:00
|
|
|
nsip_free(struct ifnet *ifp)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifnet_en *ifn = (struct ifnet_en *)ifp;
|
1993-04-09 16:00:07 +04:00
|
|
|
struct route *ro = & ifn->ifen_route;
|
|
|
|
|
|
|
|
if (ro->ro_rt) {
|
|
|
|
RTFREE(ro->ro_rt);
|
|
|
|
ro->ro_rt = 0;
|
|
|
|
}
|
|
|
|
ifp->if_flags &= ~IFF_UP;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:13:43 +03:00
|
|
|
void *
|
2004-04-19 04:10:48 +04:00
|
|
|
nsip_ctlinput(int cmd, struct sockaddr *sa, void *v)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
if ((unsigned)cmd >= PRC_NCMDS)
|
1996-10-11 03:22:58 +04:00
|
|
|
return NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (sa->sa_family != AF_INET && sa->sa_family != AF_IMPLINK)
|
1996-10-11 03:22:58 +04:00
|
|
|
return NULL;
|
1995-06-13 12:36:58 +04:00
|
|
|
sin = satosin(sa);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (sin->sin_addr.s_addr == INADDR_ANY)
|
1996-10-11 03:22:58 +04:00
|
|
|
return NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case PRC_ROUTEDEAD:
|
|
|
|
case PRC_REDIRECT_NET:
|
|
|
|
case PRC_REDIRECT_HOST:
|
|
|
|
case PRC_REDIRECT_TOSNET:
|
|
|
|
case PRC_REDIRECT_TOSHOST:
|
|
|
|
nsip_rtchange(&sin->sin_addr);
|
|
|
|
break;
|
|
|
|
}
|
1996-02-14 01:13:43 +03:00
|
|
|
return NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
1996-02-14 01:13:43 +03:00
|
|
|
void
|
2004-04-19 04:10:48 +04:00
|
|
|
nsip_rtchange(struct in_addr *dst)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifnet_en *ifn;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
for (ifn = nsip_list; ifn; ifn = ifn->ifen_next) {
|
|
|
|
if (ifn->ifen_dst.s_addr == dst->s_addr &&
|
|
|
|
ifn->ifen_route.ro_rt) {
|
|
|
|
RTFREE(ifn->ifen_route.ro_rt);
|
|
|
|
ifn->ifen_route.ro_rt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|