2003-06-27 01:49:17 +04:00
|
|
|
/* $NetBSD: ip_mroute.c,v 1.74 2003/06/26 21:49:17 itojun Exp $ */
|
2002-07-31 08:07:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1989 Stephen Deering
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Stephen Deering of Stanford University.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @(#)ip_mroute.c 8.2 (Berkeley) 11/15/93
|
|
|
|
*/
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* IP multicast forwarding procedures
|
1993-12-06 07:50:19 +03:00
|
|
|
*
|
|
|
|
* Written by David Waitzman, BBN Labs, August 1988.
|
|
|
|
* Modified by Steve Deering, Stanford, February 1989.
|
1995-06-01 01:50:34 +04:00
|
|
|
* Modified by Mark J. Steiglitz, Stanford, May, 1991
|
|
|
|
* Modified by Van Jacobson, LBL, January 1993
|
|
|
|
* Modified by Ajit Thyagarajan, PARC, August 1993
|
|
|
|
* Modified by Bill Fenner, PARC, April 1994
|
|
|
|
* Modified by Charles M. Hannum, NetBSD, May 1995.
|
1993-12-06 07:50:19 +03:00
|
|
|
*
|
1995-06-01 01:50:34 +04:00
|
|
|
* MROUTING Revision: 1.2
|
1993-12-06 07:50:19 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 03:32:34 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-06-27 01:49:17 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.74 2003/06/26 21:49:17 itojun Exp $");
|
2001-11-13 03:32:34 +03:00
|
|
|
|
1999-07-10 02:57:15 +04:00
|
|
|
#include "opt_ipsec.h"
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
#include <sys/param.h>
|
1995-06-01 01:50:34 +04:00
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1993-12-06 07:50:19 +03:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1995-06-01 01:50:34 +04:00
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/errno.h>
|
1993-12-06 07:50:19 +03:00
|
|
|
#include <sys/time.h>
|
1995-06-01 01:50:34 +04:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/syslog.h>
|
1993-12-06 07:50:19 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/raw_cb.h>
|
|
|
|
#include <netinet/in.h>
|
1995-06-01 01:50:34 +04:00
|
|
|
#include <netinet/in_var.h>
|
1993-12-06 07:50:19 +03:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
1995-06-01 01:50:34 +04:00
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
#include <netinet/udp.h>
|
1993-12-06 07:50:19 +03:00
|
|
|
#include <netinet/igmp.h>
|
|
|
|
#include <netinet/igmp_var.h>
|
|
|
|
#include <netinet/ip_mroute.h>
|
2001-05-08 14:07:15 +04:00
|
|
|
#include <netinet/ip_encap.h>
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2002-11-05 05:07:25 +03:00
|
|
|
#ifdef IPSEC
|
|
|
|
#include <netinet6/ipsec.h>
|
|
|
|
#include <netkey/key.h>
|
|
|
|
#endif
|
|
|
|
|
1996-02-14 02:40:59 +03:00
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
#define IP_MULTICASTOPTS 0
|
|
|
|
#define M_PULLUP(m, len) \
|
|
|
|
do { \
|
|
|
|
if ((m) && ((m)->m_flags & M_EXT || (m)->m_len < (len))) \
|
|
|
|
(m) = m_pullup((m), (len)); \
|
2002-11-02 10:20:42 +03:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
|
|
|
* Globals. All but ip_mrouter and ip_mrtproto could be static,
|
|
|
|
* except for netstat or debugging purposes.
|
|
|
|
*/
|
1996-09-09 21:09:50 +04:00
|
|
|
struct socket *ip_mrouter = 0;
|
1995-06-01 01:50:34 +04:00
|
|
|
int ip_mrtproto = IGMP_DVMRP; /* for netstat only */
|
|
|
|
|
|
|
|
#define NO_RTE_FOUND 0x1
|
|
|
|
#define RTE_FOUND 0x2
|
|
|
|
|
|
|
|
#define MFCHASH(a, g) \
|
1996-09-09 18:51:07 +04:00
|
|
|
((((a).s_addr >> 20) ^ ((a).s_addr >> 10) ^ (a).s_addr ^ \
|
|
|
|
((g).s_addr >> 20) ^ ((g).s_addr >> 10) ^ (g).s_addr) & mfchash)
|
1995-06-01 01:50:34 +04:00
|
|
|
LIST_HEAD(mfchashhdr, mfc) *mfchashtbl;
|
|
|
|
u_long mfchash;
|
|
|
|
|
|
|
|
u_char nexpire[MFCTBLSIZ];
|
|
|
|
struct vif viftable[MAXVIFS];
|
|
|
|
struct mrtstat mrtstat;
|
|
|
|
u_int mrtdebug = 0; /* debug level */
|
|
|
|
#define DEBUG_MFC 0x02
|
|
|
|
#define DEBUG_FORWARD 0x04
|
|
|
|
#define DEBUG_EXPIRE 0x08
|
|
|
|
#define DEBUG_XMIT 0x10
|
|
|
|
u_int tbfdebug = 0; /* tbf debug level */
|
|
|
|
#ifdef RSVP_ISI
|
|
|
|
u_int rsvpdebug = 0; /* rsvp debug level */
|
|
|
|
extern struct socket *ip_rsvpd;
|
|
|
|
extern int rsvp_on;
|
|
|
|
#endif /* RSVP_ISI */
|
|
|
|
|
2001-05-08 14:07:15 +04:00
|
|
|
/* vif attachment using sys/netinet/ip_encap.c */
|
|
|
|
extern struct domain inetdomain;
|
|
|
|
static void vif_input __P((struct mbuf *, ...));
|
|
|
|
static int vif_encapcheck __P((const struct mbuf *, int, int, void *));
|
|
|
|
static struct protosw vif_protosw =
|
|
|
|
{ SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR,
|
|
|
|
vif_input, rip_output, 0, rip_ctloutput,
|
|
|
|
rip_usrreq,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
};
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
#define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
|
|
|
|
#define UPCALL_EXPIRE 6 /* number of timeouts */
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/*
|
|
|
|
* Define the token bucket filter structures
|
|
|
|
*/
|
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
#define TBF_REPROCESS (hz / 100) /* 100x / second */
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-02-14 02:40:59 +03:00
|
|
|
static int get_sg_cnt __P((struct sioc_sg_req *));
|
|
|
|
static int get_vif_cnt __P((struct sioc_vif_req *));
|
|
|
|
static int ip_mrouter_init __P((struct socket *, struct mbuf *));
|
|
|
|
static int get_version __P((struct mbuf *));
|
|
|
|
static int set_assert __P((struct mbuf *));
|
|
|
|
static int get_assert __P((struct mbuf *));
|
|
|
|
static int add_vif __P((struct mbuf *));
|
|
|
|
static int del_vif __P((struct mbuf *));
|
|
|
|
static void update_mfc __P((struct mfcctl *, struct mfc *));
|
|
|
|
static void expire_mfc __P((struct mfc *));
|
|
|
|
static int add_mfc __P((struct mbuf *));
|
|
|
|
#ifdef UPCALL_TIMING
|
|
|
|
static void collate __P((struct timeval *));
|
|
|
|
#endif
|
|
|
|
static int del_mfc __P((struct mbuf *));
|
|
|
|
static int socket_send __P((struct socket *, struct mbuf *,
|
|
|
|
struct sockaddr_in *));
|
|
|
|
static void expire_upcalls __P((void *));
|
|
|
|
#ifdef RSVP_ISI
|
|
|
|
static int ip_mdq __P((struct mbuf *, struct ifnet *, struct mfc *, vifi_t));
|
|
|
|
#else
|
|
|
|
static int ip_mdq __P((struct mbuf *, struct ifnet *, struct mfc *));
|
|
|
|
#endif
|
|
|
|
static void phyint_send __P((struct ip *, struct vif *, struct mbuf *));
|
|
|
|
static void encap_send __P((struct ip *, struct vif *, struct mbuf *));
|
|
|
|
static void tbf_control __P((struct vif *, struct mbuf *, struct ip *,
|
|
|
|
u_int32_t));
|
1996-09-09 21:14:04 +04:00
|
|
|
static void tbf_queue __P((struct vif *, struct mbuf *));
|
1996-02-14 02:40:59 +03:00
|
|
|
static void tbf_process_q __P((struct vif *));
|
|
|
|
static void tbf_reprocess_q __P((void *));
|
|
|
|
static int tbf_dq_sel __P((struct vif *, struct ip *));
|
|
|
|
static void tbf_send_packet __P((struct vif *, struct mbuf *));
|
|
|
|
static void tbf_update_tokens __P((struct vif *));
|
|
|
|
static int priority __P((struct vif *, struct ip *));
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1994-06-09 20:01:53 +04:00
|
|
|
/*
|
|
|
|
* 'Interfaces' associated with decapsulator (so we can tell
|
|
|
|
* packets that went through it from ones that get reflected
|
|
|
|
* by a broken gateway). These interfaces are never linked into
|
|
|
|
* the system ifnet list & no routes point to them. I.e., packets
|
|
|
|
* can't be sent this way. They only exist as a placeholder for
|
|
|
|
* multicast source verification.
|
|
|
|
*/
|
1995-06-02 08:23:05 +04:00
|
|
|
#if 0
|
1994-06-09 20:01:53 +04:00
|
|
|
struct ifnet multicast_decap_if[MAXVIFS];
|
1995-06-02 08:23:05 +04:00
|
|
|
#endif
|
1994-06-09 20:01:53 +04:00
|
|
|
|
1995-06-02 08:23:05 +04:00
|
|
|
#define ENCAP_TTL 64
|
|
|
|
#define ENCAP_PROTO IPPROTO_IPIP /* 4 */
|
1994-06-09 20:01:53 +04:00
|
|
|
|
|
|
|
/* prototype IP hdr for encapsulated packets */
|
|
|
|
struct ip multicast_encap_iphdr = {
|
1995-06-01 01:50:34 +04:00
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
1994-06-09 20:01:53 +04:00
|
|
|
sizeof(struct ip) >> 2, IPVERSION,
|
|
|
|
#else
|
|
|
|
IPVERSION, sizeof(struct ip) >> 2,
|
|
|
|
#endif
|
|
|
|
0, /* tos */
|
|
|
|
sizeof(struct ip), /* total length */
|
|
|
|
0, /* id */
|
|
|
|
0, /* frag offset */
|
2002-06-09 20:33:36 +04:00
|
|
|
ENCAP_TTL, ENCAP_PROTO,
|
1994-06-09 20:01:53 +04:00
|
|
|
0, /* checksum */
|
|
|
|
};
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
|
|
|
* Private variables.
|
|
|
|
*/
|
1995-06-01 01:50:34 +04:00
|
|
|
static vifi_t numvifs = 0;
|
1994-06-09 20:01:53 +04:00
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
static struct callout expire_upcalls_ch;
|
|
|
|
|
1994-06-09 20:01:53 +04:00
|
|
|
/*
|
2002-03-04 16:24:06 +03:00
|
|
|
* one-back cache used by vif_encapcheck to locate a tunnel's vif
|
1994-06-09 20:01:53 +04:00
|
|
|
* given a datagram's src ip address.
|
|
|
|
*/
|
1996-09-09 18:51:07 +04:00
|
|
|
static struct in_addr last_encap_src;
|
1994-06-09 20:01:53 +04:00
|
|
|
static struct vif *last_encap_vif;
|
|
|
|
|
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* whether or not special PIM assert processing is enabled.
|
1994-06-09 20:01:53 +04:00
|
|
|
*/
|
1995-06-01 01:50:34 +04:00
|
|
|
static int pim_assert;
|
|
|
|
/*
|
|
|
|
* Rate limit for assert notification messages, in usec
|
|
|
|
*/
|
|
|
|
#define ASSERT_MSG_TIME 3000000
|
1994-06-09 20:01:53 +04:00
|
|
|
|
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* Find a route for a given origin IP address and Multicast group address
|
|
|
|
* Type of service parameter to be added in the future!!!
|
1994-06-09 20:01:53 +04:00
|
|
|
*/
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:57:03 +04:00
|
|
|
#define MFCFIND(o, g, rt) do { \
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mfc *_rt; \
|
1996-09-09 21:09:50 +04:00
|
|
|
(rt) = 0; \
|
1995-06-01 01:50:34 +04:00
|
|
|
++mrtstat.mrts_mfc_lookups; \
|
2001-11-04 23:55:25 +03:00
|
|
|
LIST_FOREACH(_rt, &mfchashtbl[MFCHASH(o, g)], mfc_hash) { \
|
1996-09-09 18:51:07 +04:00
|
|
|
if (in_hosteq(_rt->mfc_origin, (o)) && \
|
|
|
|
in_hosteq(_rt->mfc_mcastgrp, (g)) && \
|
1996-09-09 21:09:50 +04:00
|
|
|
_rt->mfc_stall == 0) { \
|
1995-06-01 01:50:34 +04:00
|
|
|
(rt) = _rt; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
1996-09-09 21:09:50 +04:00
|
|
|
if ((rt) == 0) \
|
1995-06-01 01:50:34 +04:00
|
|
|
++mrtstat.mrts_mfc_misses; \
|
2003-05-14 20:57:03 +04:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1994-06-09 20:01:53 +04:00
|
|
|
|
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* Macros to compute elapsed time efficiently
|
|
|
|
* Borrowed from Van Jacobson's scheduling code
|
1994-06-09 20:01:53 +04:00
|
|
|
*/
|
2003-05-14 20:57:03 +04:00
|
|
|
#define TV_DELTA(a, b, delta) do { \
|
2000-03-30 16:51:13 +04:00
|
|
|
int xxs; \
|
1995-06-01 01:50:34 +04:00
|
|
|
delta = (a).tv_usec - (b).tv_usec; \
|
|
|
|
xxs = (a).tv_sec - (b).tv_sec; \
|
|
|
|
switch (xxs) { \
|
|
|
|
case 2: \
|
|
|
|
delta += 1000000; \
|
|
|
|
/* fall through */ \
|
|
|
|
case 1: \
|
|
|
|
delta += 1000000; \
|
|
|
|
/* fall through */ \
|
|
|
|
case 0: \
|
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
delta += (1000000 * xxs); \
|
|
|
|
break; \
|
|
|
|
} \
|
2003-05-14 20:57:03 +04:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1994-06-09 20:01:53 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef UPCALL_TIMING
|
|
|
|
u_int32_t upcall_data[51];
|
|
|
|
#endif /* UPCALL_TIMING */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle MRT setsockopt commands to modify the multicast routing tables.
|
|
|
|
*/
|
|
|
|
int
|
1996-06-23 16:12:44 +04:00
|
|
|
ip_mrouter_set(so, optname, m)
|
1995-06-01 01:50:34 +04:00
|
|
|
struct socket *so;
|
1996-06-23 16:12:44 +04:00
|
|
|
int optname;
|
1995-06-01 01:50:34 +04:00
|
|
|
struct mbuf **m;
|
1994-06-09 20:01:53 +04:00
|
|
|
{
|
1995-06-01 01:50:34 +04:00
|
|
|
int error;
|
1994-06-09 20:01:53 +04:00
|
|
|
|
1996-06-23 16:12:44 +04:00
|
|
|
if (optname != MRT_INIT && so != ip_mrouter)
|
|
|
|
error = ENOPROTOOPT;
|
1995-06-01 01:50:34 +04:00
|
|
|
else
|
1996-06-23 16:12:44 +04:00
|
|
|
switch (optname) {
|
1995-06-01 01:50:34 +04:00
|
|
|
case MRT_INIT:
|
|
|
|
error = ip_mrouter_init(so, *m);
|
|
|
|
break;
|
|
|
|
case MRT_DONE:
|
|
|
|
error = ip_mrouter_done();
|
|
|
|
break;
|
|
|
|
case MRT_ADD_VIF:
|
|
|
|
error = add_vif(*m);
|
|
|
|
break;
|
|
|
|
case MRT_DEL_VIF:
|
|
|
|
error = del_vif(*m);
|
|
|
|
break;
|
|
|
|
case MRT_ADD_MFC:
|
|
|
|
error = add_mfc(*m);
|
|
|
|
break;
|
|
|
|
case MRT_DEL_MFC:
|
|
|
|
error = del_mfc(*m);
|
|
|
|
break;
|
|
|
|
case MRT_ASSERT:
|
|
|
|
error = set_assert(*m);
|
|
|
|
break;
|
|
|
|
default:
|
1996-06-23 16:12:44 +04:00
|
|
|
error = ENOPROTOOPT;
|
1995-06-01 01:50:34 +04:00
|
|
|
break;
|
|
|
|
}
|
1994-06-09 20:01:53 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (*m)
|
|
|
|
m_free(*m);
|
|
|
|
return (error);
|
1994-06-09 20:01:53 +04:00
|
|
|
}
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* Handle MRT getsockopt commands
|
1993-12-06 07:50:19 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-06-23 16:12:44 +04:00
|
|
|
ip_mrouter_get(so, optname, m)
|
1995-06-01 01:50:34 +04:00
|
|
|
struct socket *so;
|
1996-06-23 16:12:44 +04:00
|
|
|
int optname;
|
1995-06-01 01:50:34 +04:00
|
|
|
struct mbuf **m;
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
1995-06-01 01:50:34 +04:00
|
|
|
int error;
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (so != ip_mrouter)
|
1996-06-23 16:12:44 +04:00
|
|
|
error = ENOPROTOOPT;
|
1995-06-01 01:50:34 +04:00
|
|
|
else {
|
1996-06-23 16:12:44 +04:00
|
|
|
*m = m_get(M_WAIT, MT_SOOPTS);
|
2003-02-26 09:31:08 +03:00
|
|
|
MCLAIM(*m, so->so_mowner);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1996-06-23 16:12:44 +04:00
|
|
|
switch (optname) {
|
1995-06-01 01:50:34 +04:00
|
|
|
case MRT_VERSION:
|
1996-06-23 16:12:44 +04:00
|
|
|
error = get_version(*m);
|
1995-06-01 01:50:34 +04:00
|
|
|
break;
|
|
|
|
case MRT_ASSERT:
|
1996-06-23 16:12:44 +04:00
|
|
|
error = get_assert(*m);
|
1995-06-01 01:50:34 +04:00
|
|
|
break;
|
|
|
|
default:
|
1996-06-23 16:12:44 +04:00
|
|
|
error = ENOPROTOOPT;
|
1995-06-01 01:50:34 +04:00
|
|
|
break;
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (error)
|
1996-06-23 16:12:44 +04:00
|
|
|
m_free(*m);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
return (error);
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/*
|
|
|
|
* Handle ioctl commands to obtain information from the cache
|
|
|
|
*/
|
|
|
|
int
|
1996-06-23 16:12:44 +04:00
|
|
|
mrt_ioctl(so, cmd, data)
|
|
|
|
struct socket *so;
|
1995-06-01 01:50:34 +04:00
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
|
|
|
int error;
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1996-06-23 16:12:44 +04:00
|
|
|
if (so != ip_mrouter)
|
1995-06-01 01:50:34 +04:00
|
|
|
error = EINVAL;
|
1996-06-23 16:12:44 +04:00
|
|
|
else
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGETVIFCNT:
|
|
|
|
error = get_vif_cnt((struct sioc_vif_req *)data);
|
|
|
|
break;
|
|
|
|
case SIOCGETSGCNT:
|
|
|
|
error = get_sg_cnt((struct sioc_sg_req *)data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/*
|
|
|
|
* returns the packet, byte, rpf-failure count for the source group provided
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
get_sg_cnt(req)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct sioc_sg_req *req;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mfc *rt;
|
1995-06-01 01:50:34 +04:00
|
|
|
int s;
|
|
|
|
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
1996-09-09 18:51:07 +04:00
|
|
|
MFCFIND(req->src, req->grp, rt);
|
1995-06-01 01:50:34 +04:00
|
|
|
splx(s);
|
1996-09-09 21:09:50 +04:00
|
|
|
if (rt != 0) {
|
1995-06-01 01:50:34 +04:00
|
|
|
req->pktcnt = rt->mfc_pkt_cnt;
|
|
|
|
req->bytecnt = rt->mfc_byte_cnt;
|
|
|
|
req->wrong_if = rt->mfc_wrong_if;
|
|
|
|
} else
|
|
|
|
req->pktcnt = req->bytecnt = req->wrong_if = 0xffffffff;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns the input and output packet and byte counts on the vif provided
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
get_vif_cnt(req)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct sioc_vif_req *req;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
vifi_t vifi = req->vifi;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
if (vifi >= numvifs)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
req->icount = viftable[vifi].v_pkt_in;
|
|
|
|
req->ocount = viftable[vifi].v_pkt_out;
|
|
|
|
req->ibytes = viftable[vifi].v_bytes_in;
|
|
|
|
req->obytes = viftable[vifi].v_bytes_out;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
|
|
|
* Enable multicast routing
|
|
|
|
*/
|
|
|
|
static int
|
1995-06-01 01:50:34 +04:00
|
|
|
ip_mrouter_init(so, m)
|
|
|
|
struct socket *so;
|
|
|
|
struct mbuf *m;
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
1995-06-01 01:50:34 +04:00
|
|
|
int *v;
|
|
|
|
|
|
|
|
if (mrtdebug)
|
|
|
|
log(LOG_DEBUG,
|
1996-09-09 21:09:50 +04:00
|
|
|
"ip_mrouter_init: so_type = %d, pr_protocol = %d\n",
|
1995-06-01 01:50:34 +04:00
|
|
|
so->so_type, so->so_proto->pr_protocol);
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
if (so->so_type != SOCK_RAW ||
|
|
|
|
so->so_proto->pr_protocol != IPPROTO_IGMP)
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (m == 0 || m->m_len < sizeof(int))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
v = mtod(m, int *);
|
|
|
|
if (*v != 1)
|
|
|
|
return (EINVAL);
|
|
|
|
|
1996-09-09 21:09:50 +04:00
|
|
|
if (ip_mrouter != 0)
|
1993-12-06 07:50:19 +03:00
|
|
|
return (EADDRINUSE);
|
|
|
|
|
|
|
|
ip_mrouter = so;
|
|
|
|
|
2000-11-08 17:28:12 +03:00
|
|
|
mfchashtbl =
|
|
|
|
hashinit(MFCTBLSIZ, HASH_LIST, M_MRTABLE, M_WAITOK, &mfchash);
|
1995-06-01 01:50:34 +04:00
|
|
|
bzero((caddr_t)nexpire, sizeof(nexpire));
|
|
|
|
|
|
|
|
pim_assert = 0;
|
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_init(&expire_upcalls_ch);
|
|
|
|
callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT,
|
|
|
|
expire_upcalls, NULL);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
if (mrtdebug)
|
1996-09-09 21:09:50 +04:00
|
|
|
log(LOG_DEBUG, "ip_mrouter_init\n");
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable multicast routing
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ip_mrouter_done()
|
|
|
|
{
|
1995-06-01 01:50:34 +04:00
|
|
|
vifi_t vifi;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp;
|
1995-06-01 01:50:34 +04:00
|
|
|
int i;
|
|
|
|
int s;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-02 08:23:05 +04:00
|
|
|
/* Clear out all the vifs currently in use. */
|
1993-12-06 07:50:19 +03:00
|
|
|
for (vifi = 0; vifi < numvifs; vifi++) {
|
1995-06-01 01:50:34 +04:00
|
|
|
vifp = &viftable[vifi];
|
1996-09-09 18:51:07 +04:00
|
|
|
if (!in_nullhost(vifp->v_lcl_addr))
|
1995-06-02 08:23:05 +04:00
|
|
|
reset_vif(vifp);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
1995-06-02 08:23:05 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
numvifs = 0;
|
1995-06-01 01:50:34 +04:00
|
|
|
pim_assert = 0;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&expire_upcalls_ch);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* Free all multicast forwarding cache entries.
|
1993-12-06 07:50:19 +03:00
|
|
|
*/
|
1995-06-01 01:50:34 +04:00
|
|
|
for (i = 0; i < MFCTBLSIZ; i++) {
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mfc *rt, *nrt;
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2001-11-04 23:55:25 +03:00
|
|
|
for (rt = LIST_FIRST(&mfchashtbl[i]); rt; rt = nrt) {
|
|
|
|
nrt = LIST_NEXT(rt, mfc_hash);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
expire_mfc(rt);
|
|
|
|
}
|
|
|
|
}
|
1999-02-01 18:09:46 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
free(mfchashtbl, M_MRTABLE);
|
1999-02-01 18:09:46 +03:00
|
|
|
mfchashtbl = 0;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-02 08:23:05 +04:00
|
|
|
/* Reset de-encapsulation cache. */
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1996-09-09 21:09:50 +04:00
|
|
|
ip_mrouter = 0;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
splx(s);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (mrtdebug)
|
1996-09-09 21:09:50 +04:00
|
|
|
log(LOG_DEBUG, "ip_mrouter_done\n");
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-06-26 07:35:00 +04:00
|
|
|
void
|
|
|
|
ip_mrouter_detach(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
int vifi, i;
|
|
|
|
struct vif *vifp;
|
|
|
|
struct mfc *rt, *nrt;
|
|
|
|
struct rtdetq *rte, *nrte, **prte;
|
|
|
|
|
|
|
|
/* XXX not sure about sideeffect to userland routing daemon */
|
|
|
|
for (vifi = 0; vifi < numvifs; vifi++) {
|
|
|
|
vifp = &viftable[vifi];
|
|
|
|
if (vifp->v_ifp == ifp)
|
|
|
|
reset_vif(vifp);
|
|
|
|
}
|
|
|
|
for (i = 0; i < MFCTBLSIZ; i++) {
|
|
|
|
for (rt = LIST_FIRST(&mfchashtbl[i]); rt; rt = nrt) {
|
2003-06-26 11:41:48 +04:00
|
|
|
nrt = LIST_NEXT(rt, mfc_hash);
|
|
|
|
|
2003-06-26 07:35:00 +04:00
|
|
|
prte = &rt->mfc_stall;
|
|
|
|
for (rte = *prte; rte; rte = nrte) {
|
|
|
|
nrte = rte->next;
|
|
|
|
if (rte->ifp == ifp) {
|
|
|
|
m_freem(rte->m);
|
|
|
|
free(rte, M_MRTABLE);
|
|
|
|
*prte = nrte;
|
|
|
|
} else
|
|
|
|
prte = &rte->next;
|
|
|
|
}
|
2003-06-26 11:41:48 +04:00
|
|
|
|
|
|
|
if (rt->mfc_expire == 0)
|
|
|
|
continue;
|
|
|
|
nexpire[i]--;
|
|
|
|
++mrtstat.mrts_cache_cleanups;
|
|
|
|
expire_mfc(rt);
|
2003-06-26 07:35:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
static int
|
|
|
|
get_version(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
int *v = mtod(m, int *);
|
|
|
|
|
|
|
|
*v = 0x0305; /* XXX !!!! */
|
|
|
|
m->m_len = sizeof(int);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set PIM assert processing global
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
set_assert(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
int *i;
|
|
|
|
|
|
|
|
if (m == 0 || m->m_len < sizeof(int))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
i = mtod(m, int *);
|
|
|
|
pim_assert = !!*i;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get PIM assert processing global
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
get_assert(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
int *i = mtod(m, int *);
|
|
|
|
|
|
|
|
*i = pim_assert;
|
|
|
|
m->m_len = sizeof(int);
|
1993-12-06 07:50:19 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
static struct sockaddr_in sin = { sizeof(sin), AF_INET };
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
|
|
|
* Add a vif to the vif table
|
|
|
|
*/
|
|
|
|
static int
|
1995-06-01 01:50:34 +04:00
|
|
|
add_vif(m)
|
|
|
|
struct mbuf *m;
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vifctl *vifcp;
|
|
|
|
struct vif *vifp;
|
1995-06-01 01:50:34 +04:00
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct ifnet *ifp;
|
1993-12-06 07:50:19 +03:00
|
|
|
struct ifreq ifr;
|
1995-06-01 01:50:34 +04:00
|
|
|
int error, s;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (m == 0 || m->m_len < sizeof(struct vifctl))
|
|
|
|
return (EINVAL);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
vifcp = mtod(m, struct vifctl *);
|
1993-12-06 07:50:19 +03:00
|
|
|
if (vifcp->vifc_vifi >= MAXVIFS)
|
|
|
|
return (EINVAL);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
vifp = &viftable[vifcp->vifc_vifi];
|
1996-09-09 18:51:07 +04:00
|
|
|
if (!in_nullhost(vifp->v_lcl_addr))
|
1993-12-06 07:50:19 +03:00
|
|
|
return (EADDRINUSE);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/* Find the interface with an address in AF_INET family. */
|
1993-12-06 07:50:19 +03:00
|
|
|
sin.sin_addr = vifcp->vifc_lcl_addr;
|
1995-06-04 09:06:49 +04:00
|
|
|
ifa = ifa_ifwithaddr(sintosa(&sin));
|
1993-12-06 07:50:19 +03:00
|
|
|
if (ifa == 0)
|
|
|
|
return (EADDRNOTAVAIL);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1994-06-09 20:01:53 +04:00
|
|
|
if (vifcp->vifc_flags & VIFF_TUNNEL) {
|
1995-06-02 08:23:05 +04:00
|
|
|
if (vifcp->vifc_flags & VIFF_SRCRT) {
|
1996-09-09 21:09:50 +04:00
|
|
|
log(LOG_ERR, "Source routed tunnels not supported\n");
|
1995-06-01 01:50:34 +04:00
|
|
|
return (EOPNOTSUPP);
|
1994-05-13 10:02:48 +04:00
|
|
|
}
|
1995-06-02 08:23:05 +04:00
|
|
|
|
2001-05-08 14:07:15 +04:00
|
|
|
/* attach this vif to decapsulator dispatch table */
|
|
|
|
vifp->v_encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4,
|
|
|
|
vif_encapcheck, &vif_protosw, vifp);
|
|
|
|
if (!vifp->v_encap_cookie)
|
|
|
|
return (EINVAL);
|
|
|
|
|
1995-06-02 08:23:05 +04:00
|
|
|
/* Create a fake encapsulation interface. */
|
|
|
|
ifp = (struct ifnet *)malloc(sizeof(*ifp), M_MRTABLE, M_WAITOK);
|
|
|
|
bzero(ifp, sizeof(*ifp));
|
1996-10-13 06:03:00 +04:00
|
|
|
sprintf(ifp->if_xname, "mdecap%d", vifcp->vifc_vifi);
|
1995-06-02 08:23:05 +04:00
|
|
|
|
|
|
|
/* Prepare cached route entry. */
|
|
|
|
bzero(&vifp->v_route, sizeof(vifp->v_route));
|
1994-06-09 20:01:53 +04:00
|
|
|
} else {
|
1995-06-02 08:23:05 +04:00
|
|
|
/* Use the physical interface associated with the address. */
|
|
|
|
ifp = ifa->ifa_ifp;
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/* Make sure the interface supports multicast. */
|
1994-06-09 20:01:53 +04:00
|
|
|
if ((ifp->if_flags & IFF_MULTICAST) == 0)
|
1995-06-01 01:50:34 +04:00
|
|
|
return (EOPNOTSUPP);
|
2000-02-01 03:07:50 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/* Enable promiscuous reception of all IP multicasts. */
|
1995-06-04 10:46:05 +04:00
|
|
|
satosin(&ifr.ifr_addr)->sin_len = sizeof(struct sockaddr_in);
|
1995-06-01 01:50:34 +04:00
|
|
|
satosin(&ifr.ifr_addr)->sin_family = AF_INET;
|
1996-09-09 18:51:07 +04:00
|
|
|
satosin(&ifr.ifr_addr)->sin_addr = zeroin_addr;
|
1993-12-06 07:50:19 +03:00
|
|
|
error = (*ifp->if_ioctl)(ifp, SIOCADDMULTI, (caddr_t)&ifr);
|
1994-06-09 20:01:53 +04:00
|
|
|
if (error)
|
1995-06-01 01:50:34 +04:00
|
|
|
return (error);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
2000-02-01 03:07:50 +03:00
|
|
|
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
1996-09-09 21:14:04 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/* Define parameters for the tbf structure. */
|
1996-09-09 21:14:04 +04:00
|
|
|
vifp->tbf_q = 0;
|
|
|
|
vifp->tbf_t = &vifp->tbf_q;
|
|
|
|
microtime(&vifp->tbf_last_pkt_t);
|
|
|
|
vifp->tbf_n_tok = 0;
|
|
|
|
vifp->tbf_q_len = 0;
|
|
|
|
vifp->tbf_max_q_len = MAXQSIZE;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
vifp->v_flags = vifcp->vifc_flags;
|
|
|
|
vifp->v_threshold = vifcp->vifc_threshold;
|
1996-09-09 21:14:04 +04:00
|
|
|
/* scaling up here allows division by 1024 in critical code */
|
|
|
|
vifp->v_rate_limit = vifcp->vifc_rate_limit * 1024 / 1000;
|
1993-12-06 07:50:19 +03:00
|
|
|
vifp->v_lcl_addr = vifcp->vifc_lcl_addr;
|
1995-06-01 01:50:34 +04:00
|
|
|
vifp->v_rmt_addr = vifcp->vifc_rmt_addr;
|
1994-06-09 20:01:53 +04:00
|
|
|
vifp->v_ifp = ifp;
|
1995-06-01 01:50:34 +04:00
|
|
|
/* Initialize per vif pkt counters. */
|
|
|
|
vifp->v_pkt_in = 0;
|
|
|
|
vifp->v_pkt_out = 0;
|
|
|
|
vifp->v_bytes_in = 0;
|
|
|
|
vifp->v_bytes_out = 0;
|
2000-03-23 10:01:25 +03:00
|
|
|
|
|
|
|
callout_init(&vifp->v_repq_ch);
|
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
#ifdef RSVP_ISI
|
|
|
|
vifp->v_rsvp_on = 0;
|
|
|
|
vifp->v_rsvpd = 0;
|
|
|
|
#endif /* RSVP_ISI */
|
|
|
|
|
1994-06-09 20:01:53 +04:00
|
|
|
splx(s);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/* Adjust numvifs up if the vifi is higher than numvifs. */
|
1993-12-06 07:50:19 +03:00
|
|
|
if (numvifs <= vifcp->vifc_vifi)
|
|
|
|
numvifs = vifcp->vifc_vifi + 1;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (mrtdebug)
|
1996-09-09 21:09:50 +04:00
|
|
|
log(LOG_DEBUG, "add_vif #%d, lcladdr %x, %s %x, thresh %x, rate %d\n",
|
2002-06-09 20:33:36 +04:00
|
|
|
vifcp->vifc_vifi,
|
1995-06-01 01:50:34 +04:00
|
|
|
ntohl(vifcp->vifc_lcl_addr.s_addr),
|
|
|
|
(vifcp->vifc_flags & VIFF_TUNNEL) ? "rmtaddr" : "mask",
|
|
|
|
ntohl(vifcp->vifc_rmt_addr.s_addr),
|
|
|
|
vifcp->vifc_threshold,
|
2002-06-09 20:33:36 +04:00
|
|
|
vifcp->vifc_rate_limit);
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-06-02 08:23:05 +04:00
|
|
|
void
|
|
|
|
reset_vif(vifp)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp;
|
1995-06-02 08:23:05 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m, *n;
|
1995-06-02 08:23:05 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifreq ifr;
|
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&vifp->v_repq_ch);
|
|
|
|
|
2001-05-08 14:07:15 +04:00
|
|
|
/* detach this vif from decapsulator dispatch table */
|
|
|
|
encap_detach(vifp->v_encap_cookie);
|
|
|
|
vifp->v_encap_cookie = NULL;
|
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
for (m = vifp->tbf_q; m != 0; m = n) {
|
|
|
|
n = m->m_nextpkt;
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
|
1995-06-02 08:23:05 +04:00
|
|
|
if (vifp->v_flags & VIFF_TUNNEL) {
|
|
|
|
free(vifp->v_ifp, M_MRTABLE);
|
|
|
|
if (vifp == last_encap_vif) {
|
|
|
|
last_encap_vif = 0;
|
1996-09-09 18:51:07 +04:00
|
|
|
last_encap_src = zeroin_addr;
|
1995-06-02 08:23:05 +04:00
|
|
|
}
|
|
|
|
} else {
|
1995-06-04 10:46:05 +04:00
|
|
|
satosin(&ifr.ifr_addr)->sin_len = sizeof(struct sockaddr_in);
|
1995-06-02 08:23:05 +04:00
|
|
|
satosin(&ifr.ifr_addr)->sin_family = AF_INET;
|
1996-09-09 18:51:07 +04:00
|
|
|
satosin(&ifr.ifr_addr)->sin_addr = zeroin_addr;
|
1995-06-02 08:23:05 +04:00
|
|
|
ifp = vifp->v_ifp;
|
|
|
|
(*ifp->if_ioctl)(ifp, SIOCDELMULTI, (caddr_t)&ifr);
|
|
|
|
}
|
|
|
|
bzero((caddr_t)vifp, sizeof(*vifp));
|
|
|
|
}
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
|
|
|
* Delete a vif from the vif table
|
|
|
|
*/
|
|
|
|
static int
|
1995-06-01 01:50:34 +04:00
|
|
|
del_vif(m)
|
|
|
|
struct mbuf *m;
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
1995-06-01 01:50:34 +04:00
|
|
|
vifi_t *vifip;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp;
|
|
|
|
vifi_t vifi;
|
1995-06-01 01:50:34 +04:00
|
|
|
int s;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (m == 0 || m->m_len < sizeof(vifi_t))
|
|
|
|
return (EINVAL);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
vifip = mtod(m, vifi_t *);
|
1993-12-06 07:50:19 +03:00
|
|
|
if (*vifip >= numvifs)
|
|
|
|
return (EINVAL);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
vifp = &viftable[*vifip];
|
1996-09-09 18:51:07 +04:00
|
|
|
if (in_nullhost(vifp->v_lcl_addr))
|
1993-12-06 07:50:19 +03:00
|
|
|
return (EADDRNOTAVAIL);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-02 08:23:05 +04:00
|
|
|
reset_vif(vifp);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/* Adjust numvifs down */
|
1995-06-01 01:50:34 +04:00
|
|
|
for (vifi = numvifs; vifi > 0; vifi--)
|
1996-09-09 18:51:07 +04:00
|
|
|
if (!in_nullhost(viftable[vifi-1].v_lcl_addr))
|
1993-12-06 07:50:19 +03:00
|
|
|
break;
|
1995-06-01 01:50:34 +04:00
|
|
|
numvifs = vifi;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
splx(s);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (mrtdebug)
|
1996-09-09 21:09:50 +04:00
|
|
|
log(LOG_DEBUG, "del_vif %d, numvifs %d\n", *vifip, numvifs);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
static void
|
|
|
|
update_mfc(mfccp, rt)
|
|
|
|
struct mfcctl *mfccp;
|
|
|
|
struct mfc *rt;
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
1995-06-01 01:50:34 +04:00
|
|
|
vifi_t vifi;
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
rt->mfc_parent = mfccp->mfcc_parent;
|
|
|
|
for (vifi = 0; vifi < numvifs; vifi++)
|
|
|
|
rt->mfc_ttls[vifi] = mfccp->mfcc_ttls[vifi];
|
|
|
|
rt->mfc_expire = 0;
|
|
|
|
rt->mfc_stall = 0;
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
static void
|
|
|
|
expire_mfc(rt)
|
|
|
|
struct mfc *rt;
|
|
|
|
{
|
|
|
|
struct rtdetq *rte, *nrte;
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1996-09-09 21:09:50 +04:00
|
|
|
for (rte = rt->mfc_stall; rte != 0; rte = nrte) {
|
1995-06-01 01:50:34 +04:00
|
|
|
nrte = rte->next;
|
|
|
|
m_freem(rte->m);
|
|
|
|
free(rte, M_MRTABLE);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
LIST_REMOVE(rt, mfc_hash);
|
|
|
|
free(rt, M_MRTABLE);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* Add an mfc entry
|
1993-12-06 07:50:19 +03:00
|
|
|
*/
|
|
|
|
static int
|
1995-06-01 01:50:34 +04:00
|
|
|
add_mfc(m)
|
|
|
|
struct mbuf *m;
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
1995-06-01 01:50:34 +04:00
|
|
|
struct mfcctl *mfccp;
|
1996-02-14 02:40:59 +03:00
|
|
|
struct mfc *rt;
|
|
|
|
u_int32_t hash = 0;
|
1995-06-01 01:50:34 +04:00
|
|
|
struct rtdetq *rte, *nrte;
|
2000-03-30 16:51:13 +04:00
|
|
|
u_short nstl;
|
1995-06-01 01:50:34 +04:00
|
|
|
int s;
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (m == 0 || m->m_len < sizeof(struct mfcctl))
|
1993-12-06 07:50:19 +03:00
|
|
|
return (EINVAL);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
mfccp = mtod(m, struct mfcctl *);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
1996-09-09 18:51:07 +04:00
|
|
|
MFCFIND(mfccp->mfcc_origin, mfccp->mfcc_mcastgrp, rt);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/* If an entry already exists, just update the fields */
|
|
|
|
if (rt) {
|
|
|
|
if (mrtdebug & DEBUG_MFC)
|
2003-05-14 21:18:36 +04:00
|
|
|
log(LOG_DEBUG, "add_mfc update o %x g %x p %x\n",
|
1995-06-01 01:50:34 +04:00
|
|
|
ntohl(mfccp->mfcc_origin.s_addr),
|
|
|
|
ntohl(mfccp->mfcc_mcastgrp.s_addr),
|
|
|
|
mfccp->mfcc_parent);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (rt->mfc_expire)
|
|
|
|
nexpire[hash]--;
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
update_mfc(mfccp, rt);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2002-06-09 20:33:36 +04:00
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* Find the entry for which the upcall was made and update
|
|
|
|
*/
|
|
|
|
nstl = 0;
|
1996-09-09 18:51:07 +04:00
|
|
|
hash = MFCHASH(mfccp->mfcc_origin, mfccp->mfcc_mcastgrp);
|
2001-11-04 23:55:25 +03:00
|
|
|
LIST_FOREACH(rt, &mfchashtbl[hash], mfc_hash) {
|
1996-09-09 18:51:07 +04:00
|
|
|
if (in_hosteq(rt->mfc_origin, mfccp->mfcc_origin) &&
|
|
|
|
in_hosteq(rt->mfc_mcastgrp, mfccp->mfcc_mcastgrp) &&
|
1996-09-09 21:09:50 +04:00
|
|
|
rt->mfc_stall != 0) {
|
1995-06-01 01:50:34 +04:00
|
|
|
if (nstl++)
|
1996-09-09 21:09:50 +04:00
|
|
|
log(LOG_ERR, "add_mfc %s o %x g %x p %x dbx %p\n",
|
1995-06-01 01:50:34 +04:00
|
|
|
"multiple kernel entries",
|
|
|
|
ntohl(mfccp->mfcc_origin.s_addr),
|
|
|
|
ntohl(mfccp->mfcc_mcastgrp.s_addr),
|
|
|
|
mfccp->mfcc_parent, rt->mfc_stall);
|
|
|
|
|
|
|
|
if (mrtdebug & DEBUG_MFC)
|
2003-05-14 21:18:36 +04:00
|
|
|
log(LOG_DEBUG, "add_mfc o %x g %x p %x dbg %p\n",
|
1995-06-01 01:50:34 +04:00
|
|
|
ntohl(mfccp->mfcc_origin.s_addr),
|
|
|
|
ntohl(mfccp->mfcc_mcastgrp.s_addr),
|
|
|
|
mfccp->mfcc_parent, rt->mfc_stall);
|
|
|
|
|
|
|
|
if (rt->mfc_expire)
|
|
|
|
nexpire[hash]--;
|
|
|
|
|
1997-08-14 10:42:33 +04:00
|
|
|
rte = rt->mfc_stall;
|
|
|
|
update_mfc(mfccp, rt);
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/* free packets Qed at the end of this entry */
|
1997-08-14 10:42:33 +04:00
|
|
|
for (; rte != 0; rte = nrte) {
|
1995-06-01 01:50:34 +04:00
|
|
|
nrte = rte->next;
|
|
|
|
#ifdef RSVP_ISI
|
|
|
|
ip_mdq(rte->m, rte->ifp, rt, -1);
|
|
|
|
#else
|
|
|
|
ip_mdq(rte->m, rte->ifp, rt);
|
|
|
|
#endif /* RSVP_ISI */
|
|
|
|
m_freem(rte->m);
|
|
|
|
#ifdef UPCALL_TIMING
|
|
|
|
collate(&rte->t);
|
|
|
|
#endif /* UPCALL_TIMING */
|
|
|
|
free(rte, M_MRTABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (nstl == 0) {
|
|
|
|
/*
|
|
|
|
* No mfc; make a new one
|
|
|
|
*/
|
|
|
|
if (mrtdebug & DEBUG_MFC)
|
2003-05-14 21:18:36 +04:00
|
|
|
log(LOG_DEBUG, "add_mfc no upcall o %x g %x p %x\n",
|
1995-06-01 01:50:34 +04:00
|
|
|
ntohl(mfccp->mfcc_origin.s_addr),
|
|
|
|
ntohl(mfccp->mfcc_mcastgrp.s_addr),
|
|
|
|
mfccp->mfcc_parent);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
rt = (struct mfc *)malloc(sizeof(*rt), M_MRTABLE, M_NOWAIT);
|
1996-09-09 21:09:50 +04:00
|
|
|
if (rt == 0) {
|
1993-12-06 07:50:19 +03:00
|
|
|
splx(s);
|
1995-06-01 01:50:34 +04:00
|
|
|
return (ENOBUFS);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
rt->mfc_origin = mfccp->mfcc_origin;
|
|
|
|
rt->mfc_mcastgrp = mfccp->mfcc_mcastgrp;
|
|
|
|
/* initialize pkt counters per src-grp */
|
|
|
|
rt->mfc_pkt_cnt = 0;
|
|
|
|
rt->mfc_byte_cnt = 0;
|
|
|
|
rt->mfc_wrong_if = 0;
|
|
|
|
timerclear(&rt->mfc_last_assert);
|
|
|
|
update_mfc(mfccp, rt);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/* insert new entry at head of hash chain */
|
|
|
|
LIST_INSERT_HEAD(&mfchashtbl[hash], rt, mfc_hash);
|
|
|
|
}
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef UPCALL_TIMING
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
2002-06-09 20:33:36 +04:00
|
|
|
* collect delay statistics on the upcalls
|
1995-06-01 01:50:34 +04:00
|
|
|
*/
|
|
|
|
static void collate(t)
|
2003-05-14 20:43:44 +04:00
|
|
|
struct timeval *t;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
u_int32_t d;
|
|
|
|
struct timeval tp;
|
|
|
|
u_int32_t delta;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
microtime(&tp);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (timercmp(t, &tp, <)) {
|
|
|
|
TV_DELTA(tp, *t, delta);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
d = delta >> 10;
|
|
|
|
if (d > 50)
|
|
|
|
d = 50;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
++upcall_data[d];
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
#endif /* UPCALL_TIMING */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete an mfc entry
|
1993-12-06 07:50:19 +03:00
|
|
|
*/
|
|
|
|
static int
|
1995-06-01 01:50:34 +04:00
|
|
|
del_mfc(m)
|
|
|
|
struct mbuf *m;
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
1995-06-01 01:50:34 +04:00
|
|
|
struct mfcctl *mfccp;
|
|
|
|
struct mfc *rt;
|
1993-12-06 07:50:19 +03:00
|
|
|
int s;
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (m == 0 || m->m_len < sizeof(struct mfcctl))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
mfccp = mtod(m, struct mfcctl *);
|
|
|
|
|
|
|
|
if (mrtdebug & DEBUG_MFC)
|
1996-09-09 21:09:50 +04:00
|
|
|
log(LOG_DEBUG, "del_mfc origin %x mcastgrp %x\n",
|
1996-09-09 18:51:07 +04:00
|
|
|
ntohl(mfccp->mfcc_origin.s_addr),
|
|
|
|
ntohl(mfccp->mfcc_mcastgrp.s_addr));
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1996-09-09 18:51:07 +04:00
|
|
|
MFCFIND(mfccp->mfcc_origin, mfccp->mfcc_mcastgrp, rt);
|
1996-09-09 21:09:50 +04:00
|
|
|
if (rt == 0) {
|
1993-12-06 07:50:19 +03:00
|
|
|
splx(s);
|
1995-06-01 01:50:34 +04:00
|
|
|
return (EADDRNOTAVAIL);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
LIST_REMOVE(rt, mfc_hash);
|
|
|
|
free(rt, M_MRTABLE);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1995-06-01 01:50:34 +04:00
|
|
|
socket_send(s, mm, src)
|
2003-05-14 20:43:44 +04:00
|
|
|
struct socket *s;
|
|
|
|
struct mbuf *mm;
|
|
|
|
struct sockaddr_in *src;
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
if (s) {
|
|
|
|
if (sbappendaddr(&s->so_rcv, sintosa(src), mm,
|
|
|
|
(struct mbuf *)0) != 0) {
|
|
|
|
sorwakeup(s);
|
|
|
|
return (0);
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
2003-05-14 20:43:44 +04:00
|
|
|
m_freem(mm);
|
|
|
|
return (-1);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IP multicast forwarding function. This function assumes that the packet
|
|
|
|
* pointed to by "ip" has arrived on (or is about to be sent to) the interface
|
|
|
|
* pointed to by "ifp", and the packet is to be relayed to other networks
|
|
|
|
* that have members of the packet's destination IP multicast group.
|
|
|
|
*
|
1995-06-01 01:50:34 +04:00
|
|
|
* The packet is returned unscathed to the caller, unless it is
|
|
|
|
* erroneous, in which case a non-zero return value tells the caller to
|
1993-12-06 07:50:19 +03:00
|
|
|
* discard it.
|
|
|
|
*/
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
#define IP_HDR_LEN 20 /* # bytes of fixed IP header (excluding options) */
|
|
|
|
#define TUNNEL_LEN 12 /* # bytes of IP option for tunnel encapsulation */
|
1993-12-06 07:50:19 +03:00
|
|
|
|
|
|
|
int
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef RSVP_ISI
|
|
|
|
ip_mforward(m, ifp, imo)
|
|
|
|
#else
|
1994-05-13 10:02:48 +04:00
|
|
|
ip_mforward(m, ifp)
|
1995-06-01 01:50:34 +04:00
|
|
|
#endif /* RSVP_ISI */
|
2003-05-14 20:43:44 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef RSVP_ISI
|
2003-05-14 20:43:44 +04:00
|
|
|
struct ip_moptions *imo;
|
1995-06-01 01:50:34 +04:00
|
|
|
#endif /* RSVP_ISI */
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
struct ip *ip = mtod(m, struct ip *);
|
|
|
|
struct mfc *rt;
|
|
|
|
static int srctun = 0;
|
|
|
|
struct mbuf *mm;
|
|
|
|
int s;
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef RSVP_ISI
|
2003-05-14 20:43:44 +04:00
|
|
|
struct vif *vifp;
|
|
|
|
vifi_t vifi;
|
1995-06-01 01:50:34 +04:00
|
|
|
#endif /* RSVP_ISI */
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
2003-05-14 20:43:44 +04:00
|
|
|
* Clear any in-bound checksum flags for this packet.
|
1993-12-06 07:50:19 +03:00
|
|
|
*/
|
2003-05-14 20:43:44 +04:00
|
|
|
m->m_pkthdr.csum_flags = 0;
|
|
|
|
|
|
|
|
if (mrtdebug & DEBUG_FORWARD)
|
2003-05-14 21:28:31 +04:00
|
|
|
log(LOG_DEBUG, "ip_mforward: src %x, dst %x, ifp %p\n",
|
|
|
|
ntohl(ip->ip_src.s_addr), ntohl(ip->ip_dst.s_addr), ifp);
|
2003-05-14 20:43:44 +04:00
|
|
|
|
|
|
|
if (ip->ip_hl < (IP_HDR_LEN + TUNNEL_LEN) >> 2 ||
|
|
|
|
((u_char *)(ip + 1))[1] != IPOPT_LSRR) {
|
|
|
|
/*
|
|
|
|
* Packet arrived via a physical interface or
|
|
|
|
* an encapuslated tunnel.
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Packet arrived through a source-route tunnel.
|
|
|
|
* Source-route tunnels are no longer supported.
|
|
|
|
*/
|
|
|
|
if ((srctun++ % 1000) == 0)
|
|
|
|
log(LOG_ERR,
|
|
|
|
"ip_mforward: received source-routed packet from %x\n",
|
|
|
|
ntohl(ip->ip_src.s_addr));
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
return (1);
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
#ifdef RSVP_ISI
|
2003-05-14 20:43:44 +04:00
|
|
|
if (imo && ((vifi = imo->imo_multicast_vif) < numvifs)) {
|
|
|
|
if (ip->ip_ttl < 255)
|
|
|
|
ip->ip_ttl++; /* compensate for -1 in *_send routines */
|
|
|
|
if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
|
|
|
|
vifp = viftable + vifi;
|
|
|
|
printf("Sending IPPROTO_RSVP from %x to %x on vif %d (%s%s)\n",
|
|
|
|
ntohl(ip->ip_src), ntohl(ip->ip_dst), vifi,
|
|
|
|
(vifp->v_flags & VIFF_TUNNEL) ? "tunnel on " : "",
|
|
|
|
vifp->v_ifp->if_xname);
|
|
|
|
}
|
|
|
|
return (ip_mdq(m, ifp, (struct mfc *)0, vifi));
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
|
2003-05-14 20:43:44 +04:00
|
|
|
printf("Warning: IPPROTO_RSVP from %x to %x without vif option\n",
|
|
|
|
ntohl(ip->ip_src), ntohl(ip->ip_dst));
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
#endif /* RSVP_ISI */
|
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/*
|
|
|
|
* Don't forward a packet with time-to-live of zero or one,
|
|
|
|
* or a packet destined to a local-only group.
|
|
|
|
*/
|
|
|
|
if (ip->ip_ttl <= 1 || IN_LOCAL_GROUP(ip->ip_dst.s_addr))
|
|
|
|
return (0);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/*
|
|
|
|
* Determine forwarding vifs from the forwarding cache table
|
|
|
|
*/
|
|
|
|
s = splsoftnet();
|
|
|
|
MFCFIND(ip->ip_src, ip->ip_dst, rt);
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/* Entry exists, so forward if necessary */
|
|
|
|
if (rt != 0) {
|
|
|
|
splx(s);
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef RSVP_ISI
|
2003-05-14 20:43:44 +04:00
|
|
|
return (ip_mdq(m, ifp, rt, -1));
|
1995-06-01 01:50:34 +04:00
|
|
|
#else
|
2003-05-14 20:43:44 +04:00
|
|
|
return (ip_mdq(m, ifp, rt));
|
1995-06-01 01:50:34 +04:00
|
|
|
#endif /* RSVP_ISI */
|
2003-05-14 20:43:44 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If we don't have a route for packet's origin,
|
|
|
|
* Make a copy of the packet &
|
|
|
|
* send message to routing daemon
|
|
|
|
*/
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
struct mbuf *mb0;
|
|
|
|
struct rtdetq *rte;
|
|
|
|
u_int32_t hash;
|
|
|
|
int hlen = ip->ip_hl << 2;
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef UPCALL_TIMING
|
2003-05-14 20:43:44 +04:00
|
|
|
struct timeval tp;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
microtime(&tp);
|
1995-06-01 01:50:34 +04:00
|
|
|
#endif /* UPCALL_TIMING */
|
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
mrtstat.mrts_no_route++;
|
|
|
|
if (mrtdebug & (DEBUG_FORWARD | DEBUG_MFC))
|
|
|
|
log(LOG_DEBUG, "ip_mforward: no rte s %x g %x\n",
|
|
|
|
ntohl(ip->ip_src.s_addr),
|
|
|
|
ntohl(ip->ip_dst.s_addr));
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/*
|
|
|
|
* Allocate mbufs early so that we don't do extra work if we are
|
|
|
|
* just going to fail anyway. Make sure to pullup the header so
|
|
|
|
* that other people can't step on it.
|
|
|
|
*/
|
|
|
|
rte = (struct rtdetq *)malloc(sizeof(*rte), M_MRTABLE,
|
|
|
|
M_NOWAIT);
|
|
|
|
if (rte == 0) {
|
|
|
|
splx(s);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
mb0 = m_copy(m, 0, M_COPYALL);
|
|
|
|
M_PULLUP(mb0, hlen);
|
|
|
|
if (mb0 == 0) {
|
|
|
|
free(rte, M_MRTABLE);
|
|
|
|
splx(s);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/* is there an upcall waiting for this packet? */
|
|
|
|
hash = MFCHASH(ip->ip_src, ip->ip_dst);
|
|
|
|
LIST_FOREACH(rt, &mfchashtbl[hash], mfc_hash) {
|
|
|
|
if (in_hosteq(ip->ip_src, rt->mfc_origin) &&
|
|
|
|
in_hosteq(ip->ip_dst, rt->mfc_mcastgrp) &&
|
|
|
|
rt->mfc_stall != 0)
|
|
|
|
break;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (rt == 0) {
|
|
|
|
int i;
|
|
|
|
struct igmpmsg *im;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/* no upcall, so make a new entry */
|
|
|
|
rt = (struct mfc *)malloc(sizeof(*rt), M_MRTABLE,
|
|
|
|
M_NOWAIT);
|
|
|
|
if (rt == 0) {
|
|
|
|
free(rte, M_MRTABLE);
|
|
|
|
m_freem(mb0);
|
|
|
|
splx(s);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Make a copy of the header to send to the user level
|
|
|
|
* process
|
|
|
|
*/
|
|
|
|
mm = m_copy(m, 0, hlen);
|
|
|
|
M_PULLUP(mm, hlen);
|
|
|
|
if (mm == 0) {
|
|
|
|
free(rte, M_MRTABLE);
|
|
|
|
m_freem(mb0);
|
|
|
|
free(rt, M_MRTABLE);
|
|
|
|
splx(s);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/*
|
|
|
|
* Send message to routing daemon to install
|
|
|
|
* a route into the kernel table
|
|
|
|
*/
|
|
|
|
sin.sin_addr = ip->ip_src;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
im = mtod(mm, struct igmpmsg *);
|
|
|
|
im->im_msgtype = IGMPMSG_NOCACHE;
|
|
|
|
im->im_mbz = 0;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
mrtstat.mrts_upcalls++;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (socket_send(ip_mrouter, mm, &sin) < 0) {
|
|
|
|
log(LOG_WARNING,
|
|
|
|
"ip_mforward: ip_mrouter socket queue full\n");
|
|
|
|
++mrtstat.mrts_upq_sockfull;
|
|
|
|
free(rte, M_MRTABLE);
|
|
|
|
m_freem(mb0);
|
|
|
|
free(rt, M_MRTABLE);
|
|
|
|
splx(s);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* insert new entry at head of hash chain */
|
|
|
|
rt->mfc_origin = ip->ip_src;
|
|
|
|
rt->mfc_mcastgrp = ip->ip_dst;
|
|
|
|
rt->mfc_pkt_cnt = 0;
|
|
|
|
rt->mfc_byte_cnt = 0;
|
|
|
|
rt->mfc_wrong_if = 0;
|
|
|
|
rt->mfc_expire = UPCALL_EXPIRE;
|
|
|
|
nexpire[hash]++;
|
|
|
|
for (i = 0; i < numvifs; i++)
|
|
|
|
rt->mfc_ttls[i] = 0;
|
|
|
|
rt->mfc_parent = -1;
|
|
|
|
|
|
|
|
/* link into table */
|
|
|
|
LIST_INSERT_HEAD(&mfchashtbl[hash], rt, mfc_hash);
|
|
|
|
/* Add this entry to the end of the queue */
|
|
|
|
rt->mfc_stall = rte;
|
|
|
|
} else {
|
|
|
|
/* determine if q has overflowed */
|
|
|
|
struct rtdetq **p;
|
|
|
|
int npkts = 0;
|
|
|
|
|
|
|
|
for (p = &rt->mfc_stall; *p != 0; p = &(*p)->next)
|
|
|
|
if (++npkts > MAX_UPQ) {
|
|
|
|
mrtstat.mrts_upq_ovflw++;
|
|
|
|
free(rte, M_MRTABLE);
|
|
|
|
m_freem(mb0);
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add this entry to the end of the queue */
|
|
|
|
*p = rte;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
rte->next = 0;
|
|
|
|
rte->m = mb0;
|
|
|
|
rte->ifp = ifp;
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef UPCALL_TIMING
|
2003-05-14 20:43:44 +04:00
|
|
|
rte->t = tp;
|
1995-06-01 01:50:34 +04:00
|
|
|
#endif /* UPCALL_TIMING */
|
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
splx(s);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
return (0);
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-02-14 02:40:59 +03:00
|
|
|
/*ARGSUSED*/
|
1993-12-06 07:50:19 +03:00
|
|
|
static void
|
1996-02-14 02:40:59 +03:00
|
|
|
expire_upcalls(v)
|
|
|
|
void *v;
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
1995-06-01 01:50:34 +04:00
|
|
|
int i;
|
|
|
|
int s;
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
for (i = 0; i < MFCTBLSIZ; i++) {
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mfc *rt, *nrt;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
if (nexpire[i] == 0)
|
|
|
|
continue;
|
|
|
|
|
2001-11-04 23:55:25 +03:00
|
|
|
for (rt = LIST_FIRST(&mfchashtbl[i]); rt; rt = nrt) {
|
|
|
|
nrt = LIST_NEXT(rt, mfc_hash);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (rt->mfc_expire == 0 || --rt->mfc_expire > 0)
|
1995-06-01 01:50:34 +04:00
|
|
|
continue;
|
|
|
|
nexpire[i]--;
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
++mrtstat.mrts_cache_cleanups;
|
|
|
|
if (mrtdebug & DEBUG_EXPIRE)
|
|
|
|
log(LOG_DEBUG,
|
1996-09-09 21:09:50 +04:00
|
|
|
"expire_upcalls: expiring (%x %x)\n",
|
1995-06-01 01:50:34 +04:00
|
|
|
ntohl(rt->mfc_origin.s_addr),
|
|
|
|
ntohl(rt->mfc_mcastgrp.s_addr));
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
expire_mfc(rt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT,
|
|
|
|
expire_upcalls, NULL);
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
/*
|
|
|
|
* Packet forwarding routine once entry in the cache is made
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
#ifdef RSVP_ISI
|
|
|
|
ip_mdq(m, ifp, rt, xmt_vif)
|
|
|
|
#else
|
|
|
|
ip_mdq(m, ifp, rt)
|
|
|
|
#endif /* RSVP_ISI */
|
2003-05-14 20:43:44 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct mfc *rt;
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef RSVP_ISI
|
2003-05-14 20:43:44 +04:00
|
|
|
vifi_t xmt_vif;
|
1995-06-01 01:50:34 +04:00
|
|
|
#endif /* RSVP_ISI */
|
1993-12-06 07:50:19 +03:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
struct ip *ip = mtod(m, struct ip *);
|
|
|
|
vifi_t vifi;
|
|
|
|
struct vif *vifp;
|
2003-06-27 01:49:17 +04:00
|
|
|
int plen = ntohs(ip->ip_len) - (ip->ip_hl << 2);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Macro to send packet on vif. Since RSVP packets don't get counted on
|
|
|
|
* input, they shouldn't get counted on output, so statistics keeping is
|
2001-07-22 17:33:58 +04:00
|
|
|
* separate.
|
1995-06-01 01:50:34 +04:00
|
|
|
*/
|
2003-05-14 21:18:36 +04:00
|
|
|
#define MC_SEND(ip, vifp, m) do { \
|
2003-05-14 20:43:44 +04:00
|
|
|
if ((vifp)->v_flags & VIFF_TUNNEL) \
|
|
|
|
encap_send((ip), (vifp), (m)); \
|
|
|
|
else \
|
|
|
|
phyint_send((ip), (vifp), (m)); \
|
2003-05-14 20:52:53 +04:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1993-12-06 07:50:19 +03:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef RSVP_ISI
|
2003-05-14 20:43:44 +04:00
|
|
|
/*
|
|
|
|
* If xmt_vif is not -1, send on only the requested vif.
|
|
|
|
*
|
|
|
|
* (since vifi_t is u_short, -1 becomes MAXUSHORT, which > numvifs.
|
|
|
|
*/
|
|
|
|
if (xmt_vif < numvifs) {
|
|
|
|
MC_SEND(ip, viftable + xmt_vif, m);
|
|
|
|
return (1);
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
#endif /* RSVP_ISI */
|
|
|
|
|
1993-12-06 07:50:19 +03:00
|
|
|
/*
|
2003-05-14 20:43:44 +04:00
|
|
|
* Don't forward if it didn't arrive from the parent vif for its origin.
|
1993-12-06 07:50:19 +03:00
|
|
|
*/
|
2003-05-14 20:43:44 +04:00
|
|
|
vifi = rt->mfc_parent;
|
|
|
|
if ((vifi >= numvifs) || (viftable[vifi].v_ifp != ifp)) {
|
|
|
|
/* came in the wrong interface */
|
|
|
|
if (mrtdebug & DEBUG_FORWARD)
|
|
|
|
log(LOG_DEBUG, "wrong if: ifp %p vifi %d vififp %p\n",
|
2003-05-14 21:18:36 +04:00
|
|
|
ifp, vifi,
|
|
|
|
vifi >= numvifs ? 0 : viftable[vifi].v_ifp);
|
2003-05-14 20:43:44 +04:00
|
|
|
++mrtstat.mrts_wrong_if;
|
|
|
|
++rt->mfc_wrong_if;
|
|
|
|
/*
|
|
|
|
* If we are doing PIM assert processing, and we are forwarding
|
|
|
|
* packets on this interface, and it is a broadcast medium
|
|
|
|
* interface (and not a tunnel), send a message to the routing
|
|
|
|
* daemon.
|
|
|
|
*/
|
|
|
|
if (pim_assert && rt->mfc_ttls[vifi] &&
|
|
|
|
(ifp->if_flags & IFF_BROADCAST) &&
|
|
|
|
!(viftable[vifi].v_flags & VIFF_TUNNEL)) {
|
|
|
|
struct mbuf *mm;
|
|
|
|
struct igmpmsg *im;
|
|
|
|
int hlen = ip->ip_hl << 2;
|
|
|
|
struct timeval now;
|
|
|
|
u_int32_t delta;
|
|
|
|
|
|
|
|
microtime(&now);
|
|
|
|
|
|
|
|
TV_DELTA(rt->mfc_last_assert, now, delta);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (delta > ASSERT_MSG_TIME) {
|
|
|
|
mm = m_copy(m, 0, hlen);
|
|
|
|
M_PULLUP(mm, hlen);
|
|
|
|
if (mm == 0) {
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
rt->mfc_last_assert = now;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
im = mtod(mm, struct igmpmsg *);
|
|
|
|
im->im_msgtype = IGMPMSG_WRONGVIF;
|
|
|
|
im->im_mbz = 0;
|
|
|
|
im->im_vif = vifi;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
sin.sin_addr = im->im_src;
|
|
|
|
|
|
|
|
socket_send(ip_mrouter, mm, &sin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
2003-05-14 20:43:44 +04:00
|
|
|
|
|
|
|
/* If I sourced this packet, it counts as output, else it was input. */
|
|
|
|
if (in_hosteq(ip->ip_src, viftable[vifi].v_lcl_addr)) {
|
|
|
|
viftable[vifi].v_pkt_out++;
|
|
|
|
viftable[vifi].v_bytes_out += plen;
|
|
|
|
} else {
|
|
|
|
viftable[vifi].v_pkt_in++;
|
|
|
|
viftable[vifi].v_bytes_in += plen;
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
2003-05-14 20:43:44 +04:00
|
|
|
rt->mfc_pkt_cnt++;
|
|
|
|
rt->mfc_byte_cnt += plen;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For each vif, decide if a copy of the packet should be forwarded.
|
|
|
|
* Forward if:
|
|
|
|
* - the ttl exceeds the vif's threshold
|
|
|
|
* - there are group members downstream on interface
|
|
|
|
*/
|
|
|
|
for (vifp = viftable, vifi = 0; vifi < numvifs; vifp++, vifi++)
|
|
|
|
if ((rt->mfc_ttls[vifi] > 0) &&
|
|
|
|
(ip->ip_ttl > rt->mfc_ttls[vifi])) {
|
|
|
|
vifp->v_pkt_out++;
|
|
|
|
vifp->v_bytes_out += plen;
|
|
|
|
MC_SEND(ip, vifp, m);
|
|
|
|
}
|
1993-12-06 07:50:19 +03:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
return (0);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RSVP_ISI
|
|
|
|
/*
|
|
|
|
* check if a vif number is legal/ok. This is used by ip_output, to export
|
2002-06-09 20:33:36 +04:00
|
|
|
* numvifs there,
|
1995-06-01 01:50:34 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
legal_vif_num(vif)
|
2003-05-14 20:43:44 +04:00
|
|
|
int vif;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
if (vif >= 0 && vif < numvifs)
|
|
|
|
return (1);
|
|
|
|
else
|
|
|
|
return (0);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
#endif /* RSVP_ISI */
|
|
|
|
|
|
|
|
static void
|
|
|
|
phyint_send(ip, vifp, m)
|
|
|
|
struct ip *ip;
|
|
|
|
struct vif *vifp;
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *mb_copy;
|
|
|
|
int hlen = ip->ip_hl << 2;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1994-06-09 20:01:53 +04:00
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* Make a new reference to the packet; make sure that
|
|
|
|
* the IP header is actually copied, not just referenced,
|
|
|
|
* so that ip_output() only scribbles on the copy.
|
1994-06-09 20:01:53 +04:00
|
|
|
*/
|
1995-06-01 01:50:34 +04:00
|
|
|
mb_copy = m_copy(m, 0, M_COPYALL);
|
|
|
|
M_PULLUP(mb_copy, hlen);
|
1996-09-09 21:09:50 +04:00
|
|
|
if (mb_copy == 0)
|
1993-12-06 07:50:19 +03:00
|
|
|
return;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
if (vifp->v_rate_limit <= 0)
|
|
|
|
tbf_send_packet(vifp, mb_copy);
|
|
|
|
else
|
2002-08-14 04:23:27 +04:00
|
|
|
tbf_control(vifp, mb_copy, mtod(mb_copy, struct ip *),
|
|
|
|
ntohs(ip->ip_len));
|
1993-12-06 07:50:19 +03:00
|
|
|
}
|
1994-06-09 20:01:53 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
encap_send(ip, vifp, m)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ip *ip;
|
|
|
|
struct vif *vifp;
|
|
|
|
struct mbuf *m;
|
1994-06-09 20:01:53 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *mb_copy;
|
|
|
|
struct ip *ip_copy;
|
2002-08-14 04:23:27 +04:00
|
|
|
int i, len = ntohs(ip->ip_len) + sizeof(multicast_encap_iphdr);
|
1994-06-09 20:01:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* copy the old packet & pullup it's IP header into the
|
|
|
|
* new mbuf so we can modify it. Try to fill the new
|
|
|
|
* mbuf since if we don't the ethernet driver will.
|
|
|
|
*/
|
1995-06-01 01:50:34 +04:00
|
|
|
MGETHDR(mb_copy, M_DONTWAIT, MT_DATA);
|
1996-09-09 21:09:50 +04:00
|
|
|
if (mb_copy == 0)
|
1994-06-09 20:01:53 +04:00
|
|
|
return;
|
1995-06-01 01:50:34 +04:00
|
|
|
mb_copy->m_data += max_linkhdr;
|
|
|
|
mb_copy->m_pkthdr.len = len;
|
1994-06-09 20:01:53 +04:00
|
|
|
mb_copy->m_len = sizeof(multicast_encap_iphdr);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1996-09-09 21:09:50 +04:00
|
|
|
if ((mb_copy->m_next = m_copy(m, 0, M_COPYALL)) == 0) {
|
1994-06-09 20:01:53 +04:00
|
|
|
m_freem(mb_copy);
|
|
|
|
return;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
i = MHLEN - max_linkhdr;
|
1994-06-09 20:01:53 +04:00
|
|
|
if (i > len)
|
|
|
|
i = len;
|
|
|
|
mb_copy = m_pullup(mb_copy, i);
|
1996-09-09 21:09:50 +04:00
|
|
|
if (mb_copy == 0)
|
1994-06-09 20:01:53 +04:00
|
|
|
return;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1994-06-09 20:01:53 +04:00
|
|
|
/*
|
|
|
|
* fill in the encapsulating IP header.
|
|
|
|
*/
|
|
|
|
ip_copy = mtod(mb_copy, struct ip *);
|
|
|
|
*ip_copy = multicast_encap_iphdr;
|
|
|
|
ip_copy->ip_id = htons(ip_id++);
|
2002-08-14 04:23:27 +04:00
|
|
|
ip_copy->ip_len = htons(len);
|
1994-06-09 20:01:53 +04:00
|
|
|
ip_copy->ip_src = vifp->v_lcl_addr;
|
|
|
|
ip_copy->ip_dst = vifp->v_rmt_addr;
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1994-06-09 20:01:53 +04:00
|
|
|
/*
|
|
|
|
* turn the encapsulated IP header back into a valid one.
|
|
|
|
*/
|
|
|
|
ip = (struct ip *)((caddr_t)ip_copy + sizeof(multicast_encap_iphdr));
|
|
|
|
--ip->ip_ttl;
|
|
|
|
ip->ip_sum = 0;
|
|
|
|
mb_copy->m_data += sizeof(multicast_encap_iphdr);
|
|
|
|
ip->ip_sum = in_cksum(mb_copy, ip->ip_hl << 2);
|
|
|
|
mb_copy->m_data -= sizeof(multicast_encap_iphdr);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
1995-06-01 01:50:34 +04:00
|
|
|
if (vifp->v_rate_limit <= 0)
|
|
|
|
tbf_send_packet(vifp, mb_copy);
|
|
|
|
else
|
2002-08-14 04:23:27 +04:00
|
|
|
tbf_control(vifp, mb_copy, ip, ntohs(ip_copy->ip_len));
|
1994-06-09 20:01:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-08 14:07:15 +04:00
|
|
|
* De-encapsulate a packet and feed it back through ip input.
|
1994-06-09 20:01:53 +04:00
|
|
|
*/
|
2001-05-08 14:07:15 +04:00
|
|
|
static void
|
|
|
|
#if __STDC__
|
|
|
|
vif_input(struct mbuf *m, ...)
|
|
|
|
#else
|
|
|
|
vif_input(m, va_alist)
|
1996-02-14 02:40:59 +03:00
|
|
|
struct mbuf *m;
|
2001-05-08 14:07:15 +04:00
|
|
|
va_dcl
|
|
|
|
#endif
|
1994-06-09 20:01:53 +04:00
|
|
|
{
|
2001-05-08 14:07:15 +04:00
|
|
|
int off, proto;
|
|
|
|
va_list ap;
|
|
|
|
struct vif *vifp;
|
2000-03-30 16:51:13 +04:00
|
|
|
int s;
|
|
|
|
struct ifqueue *ifq;
|
1996-02-14 02:40:59 +03:00
|
|
|
|
2001-05-08 14:07:15 +04:00
|
|
|
va_start(ap, m);
|
|
|
|
off = va_arg(ap, int);
|
|
|
|
proto = va_arg(ap, int);
|
|
|
|
va_end(ap);
|
1995-06-04 11:38:19 +04:00
|
|
|
|
2001-05-08 14:07:15 +04:00
|
|
|
vifp = (struct vif *)encap_getarg(m);
|
|
|
|
if (!vifp || proto != AF_INET) {
|
|
|
|
m_freem(m);
|
|
|
|
mrtstat.mrts_bad_tunnel++;
|
|
|
|
return;
|
1994-06-09 20:01:53 +04:00
|
|
|
}
|
1995-06-04 11:38:19 +04:00
|
|
|
|
2001-05-08 14:07:15 +04:00
|
|
|
m_adj(m, off);
|
1995-06-01 01:50:34 +04:00
|
|
|
m->m_pkthdr.rcvif = vifp->v_ifp;
|
1994-06-09 20:01:53 +04:00
|
|
|
ifq = &ipintrq;
|
2001-04-14 03:29:55 +04:00
|
|
|
s = splnet();
|
1994-06-09 20:01:53 +04:00
|
|
|
if (IF_QFULL(ifq)) {
|
|
|
|
IF_DROP(ifq);
|
|
|
|
m_freem(m);
|
|
|
|
} else {
|
|
|
|
IF_ENQUEUE(ifq, m);
|
|
|
|
/*
|
|
|
|
* normally we would need a "schednetisr(NETISR_IP)"
|
|
|
|
* here but we were called by ip_input and it is going
|
|
|
|
* to loop back & try to dequeue the packet we just
|
|
|
|
* queued as soon as we return so we avoid the
|
|
|
|
* unnecessary software interrrupt.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
splx(s);
|
2001-05-08 14:07:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the packet should be grabbed by us.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vif_encapcheck(m, off, proto, arg)
|
|
|
|
const struct mbuf *m;
|
|
|
|
int off;
|
|
|
|
int proto;
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct vif *vifp;
|
|
|
|
struct ip ip;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (!arg || proto != IPPROTO_IPV4)
|
|
|
|
panic("unexpected arg in vif_encapcheck");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do not grab the packet if it's not to a multicast destination or if
|
|
|
|
* we don't have an encapsulating tunnel with the source.
|
|
|
|
* Note: This code assumes that the remote site IP address
|
|
|
|
* uniquely identifies the tunnel (i.e., that this site has
|
|
|
|
* at most one tunnel with the remote site).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* LINTED const cast */
|
|
|
|
m_copydata((struct mbuf *)m, off, sizeof(ip), (caddr_t)&ip);
|
|
|
|
if (!IN_MULTICAST(ip.ip_dst.s_addr))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* LINTED const cast */
|
|
|
|
m_copydata((struct mbuf *)m, 0, sizeof(ip), (caddr_t)&ip);
|
|
|
|
if (!in_hosteq(ip.ip_src, last_encap_src)) {
|
|
|
|
vifp = (struct vif *)arg;
|
|
|
|
if (vifp->v_flags & VIFF_TUNNEL &&
|
|
|
|
in_hosteq(vifp->v_rmt_addr, ip.ip_src))
|
|
|
|
;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
last_encap_vif = vifp;
|
|
|
|
last_encap_src = ip.ip_src;
|
|
|
|
} else
|
|
|
|
vifp = last_encap_vif;
|
|
|
|
|
|
|
|
/* 32bit match, since we have checked ip_src only */
|
|
|
|
return 32;
|
1994-06-09 20:01:53 +04:00
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Token bucket filter module
|
|
|
|
*/
|
|
|
|
static void
|
1996-09-09 21:14:04 +04:00
|
|
|
tbf_control(vifp, m, ip, len)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ip *ip;
|
|
|
|
u_int32_t len;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
if (len > MAX_BKT_SIZE) {
|
|
|
|
/* drop if packet is too large */
|
|
|
|
mrtstat.mrts_pkt2large++;
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-06-04 11:20:47 +04:00
|
|
|
tbf_update_tokens(vifp);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1995-06-04 11:20:47 +04:00
|
|
|
/*
|
|
|
|
* If there are enough tokens, and the queue is empty, send this packet
|
|
|
|
* out immediately. Otherwise, try to insert it on this vif's queue.
|
|
|
|
*/
|
1996-09-09 21:14:04 +04:00
|
|
|
if (vifp->tbf_q_len == 0) {
|
|
|
|
if (len <= vifp->tbf_n_tok) {
|
|
|
|
vifp->tbf_n_tok -= len;
|
1995-06-04 11:20:47 +04:00
|
|
|
tbf_send_packet(vifp, m);
|
|
|
|
} else {
|
|
|
|
/* queue packet and timeout till later */
|
1996-09-09 21:14:04 +04:00
|
|
|
tbf_queue(vifp, m);
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&vifp->v_repq_ch, TBF_REPROCESS,
|
|
|
|
tbf_reprocess_q, vifp);
|
1995-06-04 11:20:47 +04:00
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
} else {
|
1996-09-09 21:14:04 +04:00
|
|
|
if (vifp->tbf_q_len >= vifp->tbf_max_q_len &&
|
1995-06-04 11:20:47 +04:00
|
|
|
!tbf_dq_sel(vifp, ip)) {
|
|
|
|
/* queue length too much, and couldn't make room */
|
|
|
|
mrtstat.mrts_q_overflow++;
|
|
|
|
m_freem(m);
|
|
|
|
} else {
|
|
|
|
/* queue length low enough, or made room */
|
1996-09-09 21:14:04 +04:00
|
|
|
tbf_queue(vifp, m);
|
1995-06-04 11:20:47 +04:00
|
|
|
tbf_process_q(vifp);
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-09 20:33:36 +04:00
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* adds a packet to the queue at the interface
|
|
|
|
*/
|
|
|
|
static void
|
2002-06-09 20:33:36 +04:00
|
|
|
tbf_queue(vifp, m)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp;
|
|
|
|
struct mbuf *m;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int s = splsoftnet();
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
/* insert at tail */
|
|
|
|
*vifp->tbf_t = m;
|
|
|
|
vifp->tbf_t = &m->m_nextpkt;
|
|
|
|
vifp->tbf_q_len++;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
splx(s);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-09 20:33:36 +04:00
|
|
|
/*
|
1995-06-01 01:50:34 +04:00
|
|
|
* processes the queue at the interface
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
tbf_process_q(vifp)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
int len;
|
|
|
|
int s = splsoftnet();
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
/*
|
|
|
|
* Loop through the queue at the interface and send as many packets
|
|
|
|
* as possible.
|
|
|
|
*/
|
2003-05-14 20:43:44 +04:00
|
|
|
for (m = vifp->tbf_q; m != 0; m = vifp->tbf_q) {
|
2002-08-14 04:23:27 +04:00
|
|
|
len = ntohs(mtod(m, struct ip *)->ip_len);
|
1996-09-09 21:14:04 +04:00
|
|
|
|
|
|
|
/* determine if the packet can be sent */
|
|
|
|
if (len <= vifp->tbf_n_tok) {
|
|
|
|
/* if so,
|
|
|
|
* reduce no of tokens, dequeue the packet,
|
|
|
|
* send the packet.
|
|
|
|
*/
|
|
|
|
if ((vifp->tbf_q = m->m_nextpkt) == 0)
|
|
|
|
vifp->tbf_t = &vifp->tbf_q;
|
|
|
|
--vifp->tbf_q_len;
|
|
|
|
|
|
|
|
m->m_nextpkt = 0;
|
|
|
|
vifp->tbf_n_tok -= len;
|
|
|
|
tbf_send_packet(vifp, m);
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1995-06-04 10:55:30 +04:00
|
|
|
tbf_reprocess_q(arg)
|
|
|
|
void *arg;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp = arg;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2002-06-09 20:33:36 +04:00
|
|
|
if (ip_mrouter == 0)
|
1995-06-04 10:55:30 +04:00
|
|
|
return;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1995-06-04 10:55:30 +04:00
|
|
|
tbf_update_tokens(vifp);
|
|
|
|
tbf_process_q(vifp);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
if (vifp->tbf_q_len != 0)
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&vifp->v_repq_ch, TBF_REPROCESS,
|
|
|
|
tbf_reprocess_q, vifp);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* function that will selectively discard a member of the queue
|
1996-09-09 21:14:04 +04:00
|
|
|
* based on the precedence value and the priority
|
1995-06-01 01:50:34 +04:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
tbf_dq_sel(vifp, ip)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp;
|
|
|
|
struct ip *ip;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
u_int p;
|
|
|
|
struct mbuf **mp, *m;
|
|
|
|
int s = splsoftnet();
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
p = priority(vifp, ip);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
for (mp = &vifp->tbf_q, m = *mp;
|
|
|
|
m != 0;
|
|
|
|
mp = &m->m_nextpkt, m = *mp) {
|
|
|
|
if (p > priority(vifp, mtod(m, struct ip *))) {
|
|
|
|
if ((*mp = m->m_nextpkt) == 0)
|
|
|
|
vifp->tbf_t = mp;
|
|
|
|
--vifp->tbf_q_len;
|
|
|
|
|
|
|
|
m_freem(m);
|
|
|
|
mrtstat.mrts_drop_sel++;
|
|
|
|
splx(s);
|
|
|
|
return (1);
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
1996-09-09 21:14:04 +04:00
|
|
|
splx(s);
|
|
|
|
return (0);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1996-09-09 21:14:04 +04:00
|
|
|
tbf_send_packet(vifp, m)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp;
|
|
|
|
struct mbuf *m;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
1996-09-09 21:14:04 +04:00
|
|
|
int error;
|
|
|
|
int s = splsoftnet();
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
if (vifp->v_flags & VIFF_TUNNEL) {
|
|
|
|
/* If tunnel options */
|
1999-07-01 12:12:45 +04:00
|
|
|
#ifdef IPSEC
|
2000-03-01 15:49:27 +03:00
|
|
|
/* Don't lookup socket in forwading case */
|
2001-01-24 12:04:15 +03:00
|
|
|
(void)ipsec_setsocket(m, NULL);
|
1999-07-01 12:12:45 +04:00
|
|
|
#endif
|
1996-09-09 21:14:04 +04:00
|
|
|
ip_output(m, (struct mbuf *)0, &vifp->v_route,
|
2003-05-14 21:28:31 +04:00
|
|
|
IP_FORWARDING, (struct ip_moptions *)0);
|
1996-09-09 21:14:04 +04:00
|
|
|
} else {
|
|
|
|
/* if physical interface option, extract the options and then send */
|
|
|
|
struct ip_moptions imo;
|
|
|
|
|
|
|
|
imo.imo_multicast_ifp = vifp->v_ifp;
|
|
|
|
imo.imo_multicast_ttl = mtod(m, struct ip *)->ip_ttl - 1;
|
|
|
|
imo.imo_multicast_loop = 1;
|
1995-06-01 01:50:34 +04:00
|
|
|
#ifdef RSVP_ISI
|
1996-09-09 21:14:04 +04:00
|
|
|
imo.imo_multicast_vif = -1;
|
1993-12-06 07:50:19 +03:00
|
|
|
#endif
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1999-07-01 12:12:45 +04:00
|
|
|
#ifdef IPSEC
|
2000-03-01 15:49:27 +03:00
|
|
|
/* Don't lookup socket in forwading case */
|
2001-01-24 12:04:15 +03:00
|
|
|
(void)ipsec_setsocket(m, NULL);
|
1999-07-01 12:12:45 +04:00
|
|
|
#endif
|
1996-09-09 21:14:04 +04:00
|
|
|
error = ip_output(m, (struct mbuf *)0, (struct route *)0,
|
2003-05-14 21:28:31 +04:00
|
|
|
IP_FORWARDING|IP_MULTICASTOPTS, &imo);
|
1996-09-09 21:14:04 +04:00
|
|
|
|
|
|
|
if (mrtdebug & DEBUG_XMIT)
|
1999-03-28 00:47:59 +03:00
|
|
|
log(LOG_DEBUG, "phyint_send on vif %ld err %d\n",
|
2003-05-14 20:43:44 +04:00
|
|
|
(long)(vifp - viftable), error);
|
1996-09-09 21:14:04 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* determine the current time and then
|
|
|
|
* the elapsed time (between the last time and time now)
|
|
|
|
* in milliseconds & update the no. of tokens in the bucket
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
tbf_update_tokens(vifp)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vif *vifp;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
1996-09-09 21:14:04 +04:00
|
|
|
struct timeval tp;
|
2000-03-30 16:51:13 +04:00
|
|
|
u_int32_t tm;
|
|
|
|
int s = splsoftnet();
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
microtime(&tp);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
TV_DELTA(tp, vifp->tbf_last_pkt_t, tm);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
/*
|
|
|
|
* This formula is actually
|
|
|
|
* "time in seconds" * "bytes/second".
|
|
|
|
*
|
|
|
|
* (tm / 1000000) * (v_rate_limit * 1000 * (1000/1024) / 8)
|
|
|
|
*
|
|
|
|
* The (1000/1024) was introduced in add_vif to optimize
|
|
|
|
* this divide into a shift.
|
|
|
|
*/
|
|
|
|
vifp->tbf_n_tok += tm * vifp->v_rate_limit / 8192;
|
|
|
|
vifp->tbf_last_pkt_t = tp;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
if (vifp->tbf_n_tok > MAX_BKT_SIZE)
|
|
|
|
vifp->tbf_n_tok = MAX_BKT_SIZE;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
1996-09-09 21:14:04 +04:00
|
|
|
splx(s);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
priority(vifp, ip)
|
2003-05-14 20:43:44 +04:00
|
|
|
struct vif *vifp;
|
|
|
|
struct ip *ip;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
int prio;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/* temporary hack; may add general packet classifier some day */
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/*
|
|
|
|
* The UDP port space is divided up into four priority ranges:
|
|
|
|
* [0, 16384) : unclassified - lowest priority
|
|
|
|
* [16384, 32768) : audio - highest priority
|
|
|
|
* [32768, 49152) : whiteboard - medium priority
|
|
|
|
* [49152, 65536) : video - low priority
|
|
|
|
*/
|
|
|
|
if (ip->ip_p == IPPROTO_UDP) {
|
|
|
|
struct udphdr *udp = (struct udphdr *)(((char *)ip) + (ip->ip_hl << 2));
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
switch (ntohs(udp->uh_dport) & 0xc000) {
|
|
|
|
case 0x4000:
|
|
|
|
prio = 70;
|
|
|
|
break;
|
|
|
|
case 0x8000:
|
|
|
|
prio = 60;
|
|
|
|
break;
|
|
|
|
case 0xc000:
|
|
|
|
prio = 55;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
prio = 50;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tbfdebug > 1)
|
|
|
|
log(LOG_DEBUG, "port %x prio %d\n",
|
|
|
|
ntohs(udp->uh_dport), prio);
|
|
|
|
} else
|
|
|
|
prio = 50;
|
|
|
|
|
|
|
|
return (prio);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-06-09 20:33:36 +04:00
|
|
|
* End of token bucket filter modifications
|
1995-06-01 01:50:34 +04:00
|
|
|
*/
|
|
|
|
#ifdef RSVP_ISI
|
|
|
|
int
|
|
|
|
ip_rsvp_vif_init(so, m)
|
2003-05-14 20:43:44 +04:00
|
|
|
struct socket *so;
|
|
|
|
struct mbuf *m;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
int i;
|
|
|
|
int s;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (rsvpdebug)
|
|
|
|
printf("ip_rsvp_vif_init: so_type = %d, pr_protocol = %d\n",
|
|
|
|
so->so_type, so->so_proto->pr_protocol);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (so->so_type != SOCK_RAW ||
|
|
|
|
so->so_proto->pr_protocol != IPPROTO_RSVP)
|
|
|
|
return (EOPNOTSUPP);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/* Check mbuf. */
|
|
|
|
if (m == 0 || m->m_len != sizeof(int)) {
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
i = *(mtod(m, int *));
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (rsvpdebug)
|
2003-05-14 21:18:36 +04:00
|
|
|
printf("ip_rsvp_vif_init: vif = %d rsvp_on = %d\n", i, rsvp_on);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
s = splsoftnet();
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/* Check vif. */
|
|
|
|
if (!legal_vif_num(i)) {
|
|
|
|
splx(s);
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if socket is available. */
|
|
|
|
if (viftable[i].v_rsvpd != 0) {
|
|
|
|
splx(s);
|
|
|
|
return (EADDRINUSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
viftable[i].v_rsvpd = so;
|
|
|
|
/*
|
|
|
|
* This may seem silly, but we need to be sure we don't over-increment
|
|
|
|
* the RSVP counter, in case something slips up.
|
|
|
|
*/
|
|
|
|
if (!viftable[i].v_rsvp_on) {
|
|
|
|
viftable[i].v_rsvp_on = 1;
|
|
|
|
rsvp_on++;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
splx(s);
|
2003-05-14 20:43:44 +04:00
|
|
|
return (0);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ip_rsvp_vif_done(so, m)
|
2003-05-14 20:43:44 +04:00
|
|
|
struct socket *so;
|
|
|
|
struct mbuf *m;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
int i;
|
|
|
|
int s;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (rsvpdebug)
|
|
|
|
printf("ip_rsvp_vif_done: so_type = %d, pr_protocol = %d\n",
|
|
|
|
so->so_type, so->so_proto->pr_protocol);
|
|
|
|
|
|
|
|
if (so->so_type != SOCK_RAW ||
|
|
|
|
so->so_proto->pr_protocol != IPPROTO_RSVP)
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
|
|
|
/* Check mbuf. */
|
|
|
|
if (m == 0 || m->m_len != sizeof(int)) {
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
i = *(mtod(m, int *));
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
s = splsoftnet();
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/* Check vif. */
|
|
|
|
if (!legal_vif_num(i)) {
|
|
|
|
splx(s);
|
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rsvpdebug)
|
|
|
|
printf("ip_rsvp_vif_done: v_rsvpd = %x so = %x\n",
|
|
|
|
viftable[i].v_rsvpd, so);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
viftable[i].v_rsvpd = 0;
|
|
|
|
/*
|
|
|
|
* This may seem silly, but we need to be sure we don't over-decrement
|
|
|
|
* the RSVP counter, in case something slips up.
|
|
|
|
*/
|
|
|
|
if (viftable[i].v_rsvp_on) {
|
|
|
|
viftable[i].v_rsvp_on = 0;
|
|
|
|
rsvp_on--;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
splx(s);
|
2003-05-14 20:43:44 +04:00
|
|
|
return (0);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
1996-02-14 02:40:59 +03:00
|
|
|
void
|
1995-06-01 01:50:34 +04:00
|
|
|
ip_rsvp_force_done(so)
|
2003-05-14 20:43:44 +04:00
|
|
|
struct socket *so;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
int vifi;
|
|
|
|
int s;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/* Don't bother if it is not the right type of socket. */
|
|
|
|
if (so->so_type != SOCK_RAW ||
|
|
|
|
so->so_proto->pr_protocol != IPPROTO_RSVP)
|
|
|
|
return;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
s = splsoftnet();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The socket may be attached to more than one vif...this
|
|
|
|
* is perfectly legal.
|
|
|
|
*/
|
|
|
|
for (vifi = 0; vifi < numvifs; vifi++) {
|
|
|
|
if (viftable[vifi].v_rsvpd == so) {
|
|
|
|
viftable[vifi].v_rsvpd = 0;
|
|
|
|
/*
|
|
|
|
* This may seem silly, but we need to be sure we don't
|
|
|
|
* over-decrement the RSVP counter, in case something
|
|
|
|
* slips up.
|
|
|
|
*/
|
|
|
|
if (viftable[vifi].v_rsvp_on) {
|
|
|
|
viftable[vifi].v_rsvp_on = 0;
|
|
|
|
rsvp_on--;
|
|
|
|
}
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
splx(s);
|
|
|
|
return;
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
|
1996-02-14 02:40:59 +03:00
|
|
|
void
|
1995-06-01 01:50:34 +04:00
|
|
|
rsvp_input(m, ifp)
|
2003-05-14 20:43:44 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
1995-06-01 01:50:34 +04:00
|
|
|
{
|
2003-05-14 20:43:44 +04:00
|
|
|
int vifi;
|
|
|
|
struct ip *ip = mtod(m, struct ip *);
|
|
|
|
static struct sockaddr_in rsvp_src = { sizeof(sin), AF_INET };
|
|
|
|
int s;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
if (rsvpdebug)
|
2003-05-14 21:18:36 +04:00
|
|
|
printf("rsvp_input: rsvp_on %d\n", rsvp_on);
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/*
|
|
|
|
* Can still get packets with rsvp_on = 0 if there is a local member
|
|
|
|
* of the group to which the RSVP packet is addressed. But in this
|
|
|
|
* case we want to throw the packet away.
|
|
|
|
*/
|
|
|
|
if (!rsvp_on) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/*
|
|
|
|
* If the old-style non-vif-associated socket is set, then use
|
|
|
|
* it and ignore the new ones.
|
|
|
|
*/
|
|
|
|
if (ip_rsvpd != 0) {
|
|
|
|
if (rsvpdebug)
|
|
|
|
printf("rsvp_input: "
|
|
|
|
"Sending packet up old-style socket\n");
|
|
|
|
rip_input(m); /*XXX*/
|
|
|
|
return;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
s = splsoftnet();
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
if (rsvpdebug)
|
2003-05-14 20:43:44 +04:00
|
|
|
printf("rsvp_input: check vifs\n");
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
/* Find which vif the packet arrived on. */
|
|
|
|
for (vifi = 0; vifi < numvifs; vifi++) {
|
|
|
|
if (viftable[vifi].v_ifp == ifp)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vifi == numvifs) {
|
|
|
|
/* Can't find vif packet arrived on. Drop packet. */
|
|
|
|
if (rsvpdebug)
|
|
|
|
printf("rsvp_input: "
|
|
|
|
"Can't find vif for packet...dropping it.\n");
|
|
|
|
m_freem(m);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
|
|
|
if (rsvpdebug)
|
2003-05-14 20:43:44 +04:00
|
|
|
printf("rsvp_input: check socket\n");
|
|
|
|
|
|
|
|
if (viftable[vifi].v_rsvpd == 0) {
|
|
|
|
/*
|
|
|
|
* drop packet, since there is no specific socket for this
|
|
|
|
* interface
|
|
|
|
*/
|
|
|
|
if (rsvpdebug)
|
|
|
|
printf("rsvp_input: No socket defined for vif %d\n",
|
|
|
|
vifi);
|
|
|
|
m_freem(m);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
rsvp_src.sin_addr = ip->ip_src;
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (rsvpdebug && m)
|
|
|
|
printf("rsvp_input: m->m_len = %d, sbspace() = %d\n",
|
2003-05-14 21:18:36 +04:00
|
|
|
m->m_len, sbspace(&viftable[vifi].v_rsvpd->so_rcv));
|
1995-06-01 01:50:34 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
if (socket_send(viftable[vifi].v_rsvpd, m, &rsvp_src) < 0)
|
|
|
|
if (rsvpdebug)
|
|
|
|
printf("rsvp_input: Failed to append to socket\n");
|
|
|
|
else
|
|
|
|
if (rsvpdebug)
|
|
|
|
printf("rsvp_input: send packet up\n");
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-05-14 20:43:44 +04:00
|
|
|
splx(s);
|
1995-06-01 01:50:34 +04:00
|
|
|
}
|
|
|
|
#endif /* RSVP_ISI */
|