/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
*
- * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. The rights granted to you under the
- * License may not be used to create, or enable the creation or
- * redistribution of, unlawful or unlicensed copies of an Apple operating
- * system, or to circumvent, violate, or enable the circumvention or
- * violation of, any terms of an Apple operating system software license
- * agreement.
- *
- * Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ *
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
* limitations under the License.
- *
- * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+/*
+ * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
+ * support for mandatory and extensible security protections. This notice
+ * is included in support of clause 2.2 (b) of the Apple Public License,
+ * Version 2.0.
*/
/*
* IP multicast forwarding procedures
#include <sys/kernel.h>
#include <sys/sockio.h>
#include <sys/syslog.h>
+
+#include <machine/endian.h>
+
#include <net/if.h>
#include <net/route.h>
+#include <net/kpi_protocol.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_mroute.h>
#include <netinet/udp.h>
-#ifndef NTOHL
-#if BYTE_ORDER != BIG_ENDIAN
-#define NTOHL(d) ((d) = ntohl((d)))
-#define NTOHS(d) ((d) = ntohs((u_short)(d)))
-#define HTONL(d) ((d) = htonl((d)))
-#define HTONS(d) ((d) = htons((u_short)(d)))
-#else
-#define NTOHL(d)
-#define NTOHS(d)
-#define HTONL(d)
-#define HTONS(d)
-#endif
+#if CONFIG_MACF_NET
+#include <security/mac_framework.h>
#endif
+
#ifndef MROUTING
-extern u_long _ip_mcast_src(int vifi);
+extern u_int32_t _ip_mcast_src(int vifi);
extern int _ip_mforward(struct ip *ip, struct ifnet *ifp,
struct mbuf *m, struct ip_moptions *imo);
extern int _ip_mrouter_done(void);
u_int rsvpdebug = 0;
int
-_ip_mrouter_set(so, sopt)
- struct socket *so;
- struct sockopt *sopt;
+_ip_mrouter_set(__unused struct socket *so,
+ __unused struct sockopt *sopt)
{
return(EOPNOTSUPP);
}
int
-_ip_mrouter_get(so, sopt)
- struct socket *so;
- struct sockopt *sopt;
+_ip_mrouter_get(__unused struct socket *so,
+ __unused sockopt *sopt)
{
return(EOPNOTSUPP);
}
int (*ip_mrouter_get)(struct socket *, struct sockopt *) = _ip_mrouter_get;
int
-_ip_mrouter_done()
+_ip_mrouter_done(void)
{
return(0);
}
int (*ip_mrouter_done)(void) = _ip_mrouter_done;
int
-_ip_mforward(ip, ifp, m, imo)
- struct ip *ip;
- struct ifnet *ifp;
- struct mbuf *m;
- struct ip_moptions *imo;
+_ip_mforward(__unused struct ip *ip, __unused struct ifnet *ifp,
+ __unused struct mbuf *m, __unused ip_moptions *imo)
{
return(0);
}
struct ip_moptions *) = _ip_mforward;
int
-_mrt_ioctl(int req, caddr_t data, struct proc *p)
+_mrt_ioctl(__unused int req, __unused caddr_t data, __unused struct proc *p)
{
return EOPNOTSUPP;
}
int (*mrt_ioctl)(int, caddr_t, struct proc *) = _mrt_ioctl;
void
-rsvp_input(m, iphlen) /* XXX must fixup manually */
- struct mbuf *m;
- int iphlen;
+rsvp_input(struct mbuf *m, int iphlen) /* XXX must fixup manually */
{
/* 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
* just in case it does get called, the code a little lower in ip_output
* will assign the packet a local address.
*/
-u_long
+u_int32_t
_ip_mcast_src(int vifi) { return INADDR_ANY; }
-u_long (*ip_mcast_src)(int) = _ip_mcast_src;
+u_int32_t (*ip_mcast_src)(int) = _ip_mcast_src;
int
ip_rsvp_vif_init(so, sopt)
#define NO_RTE_FOUND 0x1
#define RTE_FOUND 0x2
-static struct mfc *mfctable[MFCTBLSIZ];
-static u_char nexpire[MFCTBLSIZ];
-static struct vif viftable[MAXVIFS];
+static struct mfc *mfctable[CONFIG_MFCTBLSIZ];
+static u_char nexpire[CONFIG_MFCTBLSIZ];
+static struct vif viftable[CONFIG_MAXVIFS];
static u_int mrtdebug = 0; /* debug level */
#define DEBUG_MFC 0x02
#define DEBUG_FORWARD 0x04
* tbftable -> each vif has one of these for storing info
*/
-static struct tbf tbftable[MAXVIFS];
+static struct tbf tbftable[CONFIG_MAXVIFS];
#define TBF_REPROCESS (hz / 100) /* 100x / second */
/*
* can't be sent this way. They only exist as a placeholder for
* multicast source verification.
*/
-static struct ifnet multicast_decap_if[MAXVIFS];
+static struct ifnet multicast_decap_if[CONFIG_MAXVIFS];
#define ENCAP_TTL 64
#define ENCAP_PROTO IPPROTO_IPIP /* 4 */
0, /* frag offset */
ENCAP_TTL, ENCAP_PROTO,
0, /* checksum */
+ { 0 }, { 0 }
};
/*
* one-back cache used by ipip_input to locate a tunnel's vif
* given a datagram's src ip address.
*/
-static u_long last_encap_src;
+static u_int32_t last_encap_src;
static struct vif *last_encap_vif;
-static u_long X_ip_mcast_src(int vifi);
+static u_int32_t X_ip_mcast_src(int vifi);
static int X_ip_mforward(struct ip *ip, struct ifnet *ifp, struct mbuf *m, struct ip_moptions *imo);
static int X_ip_mrouter_done(void);
static int X_ip_mrouter_get(struct socket *so, struct sockopt *m);
vifi_t);
static void phyint_send(struct ip *, struct vif *, struct mbuf *);
static void encap_send(struct ip *, struct vif *, struct mbuf *);
-static void tbf_control(struct vif *, struct mbuf *, struct ip *, u_long);
+static void tbf_control(struct vif *, struct mbuf *, struct ip *, u_int32_t);
static void tbf_queue(struct vif *, struct mbuf *);
static void tbf_process_q(struct vif *);
static void tbf_reprocess_q(void *);
*/
#define MFCFIND(o, g, rt) { \
- register struct mfc *_rt = mfctable[MFCHASH(o,g)]; \
+ struct mfc *_rt = mfctable[MFCHASH(o,g)]; \
rt = NULL; \
++mrtstat.mrts_mfc_lookups; \
while (_rt) { \
* Borrowed from Van Jacobson's scheduling code
*/
#define TV_DELTA(a, b, delta) { \
- register int xxs; \
+ int xxs; \
\
delta = (a).tv_usec - (b).tv_usec; \
if ((xxs = (a).tv_sec - (b).tv_sec)) { \
(a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
#if UPCALL_TIMING
-u_long upcall_data[51];
+u_int32_t upcall_data[51];
static void collate(struct timeval *);
#endif /* UPCALL_TIMING */
* Handle MRT setsockopt commands to modify the multicast routing tables.
*/
static int
-X_ip_mrouter_set(so, sopt)
- struct socket *so;
- struct sockopt *sopt;
+X_ip_mrouter_set(struct socket *so, struct sockopt *sopt)
{
int error, optval;
vifi_t vifi;
* Handle MRT getsockopt commands
*/
static int
-X_ip_mrouter_get(so, sopt)
- struct socket *so;
- struct sockopt *sopt;
+X_ip_mrouter_get(__unused struct socket *so, struct sockopt *sopt)
{
int error;
- static int version = 0x0305; /* !!! why is this here? XXX */
+ static int vers = 0x0305; /* !!! why is this here? XXX */
switch (sopt->sopt_name) {
case MRT_VERSION:
- error = sooptcopyout(sopt, &version, sizeof version);
+ error = sooptcopyout(sopt, &vers, sizeof vers);
break;
case MRT_ASSERT:
* Handle ioctl commands to obtain information from the cache
*/
static int
-X_mrt_ioctl(cmd, data)
- int cmd;
- caddr_t data;
+X_mrt_ioctl(int cmd, caddr_t data)
{
int error = 0;
* returns the packet, byte, rpf-failure count for the source group provided
*/
static int
-get_sg_cnt(req)
- register struct sioc_sg_req *req;
+get_sg_cnt(struct sioc_sg_req *req)
{
- register struct mfc *rt;
- int s;
+ struct mfc *rt;
- s = splnet();
MFCFIND(req->src.s_addr, req->grp.s_addr, rt);
- splx(s);
if (rt != NULL) {
req->pktcnt = rt->mfc_pkt_cnt;
req->bytecnt = rt->mfc_byte_cnt;
* returns the input and output packet and byte counts on the vif provided
*/
static int
-get_vif_cnt(req)
- register struct sioc_vif_req *req;
+get_vif_cnt(struct sioc_vif_req *req)
{
- register vifi_t vifi = req->vifi;
+ vifi_t vifi = req->vifi;
if (vifi >= numvifs) return EINVAL;
* Enable multicast routing
*/
static int
-ip_mrouter_init(so, version)
- struct socket *so;
- int version;
+ip_mrouter_init(struct socket *so, int vers)
{
if (mrtdebug)
log(LOG_DEBUG,"ip_mrouter_init: so_type = %d, pr_protocol = %d\n",
if (so->so_type != SOCK_RAW ||
so->so_proto->pr_protocol != IPPROTO_IGMP) return EOPNOTSUPP;
- if (version != 1)
+ if (vers != 1)
return ENOPROTOOPT;
if (ip_mrouter != NULL) return EADDRINUSE;
* Disable multicast routing
*/
static int
-X_ip_mrouter_done()
+X_ip_mrouter_done(void)
{
vifi_t vifi;
int i;
struct ifreq ifr;
struct mfc *rt;
struct rtdetq *rte;
- int s;
-
- s = splnet();
/*
* For each phyint in use, disable promiscuous reception of all IP
/*
* Free all multicast forwarding cache entries.
*/
- for (i = 0; i < MFCTBLSIZ; i++) {
+ for (i = 0; i < CONFIG_MFCTBLSIZ; i++) {
for (rt = mfctable[i]; rt != NULL; ) {
struct mfc *nr = rt->mfc_next;
ip_mrouter = NULL;
- splx(s);
-
if (mrtdebug)
log(LOG_DEBUG, "ip_mrouter_done\n");
* Set PIM assert processing global
*/
static int
-set_assert(i)
- int i;
+set_assert(int i)
{
if ((i != 1) && (i != 0))
return EINVAL;
* Add a vif to the vif table
*/
static int
-add_vif(vifcp)
- register struct vifctl *vifcp;
+add_vif(struct vifctl *vifcp)
{
- register struct vif *vifp = viftable + vifcp->vifc_vifi;
- static struct sockaddr_in sin = {sizeof sin, AF_INET};
+ struct vif *vifp = viftable + vifcp->vifc_vifi;
+ static struct sockaddr_in sin = { sizeof sin, AF_INET,
+ 0 , {0}, {0,0,0,0,0,0,0,0,} };
struct ifaddr *ifa;
struct ifnet *ifp;
int error, s;
struct tbf *v_tbf = tbftable + vifcp->vifc_vifi;
- if (vifcp->vifc_vifi >= MAXVIFS) return EINVAL;
+ if (vifcp->vifc_vifi >= CONFIG_MAXVIFS) return EINVAL;
if (vifp->v_lcl_addr.s_addr != 0) return EADDRINUSE;
/* Find the interface with an address in AF_INET family */
*/
if (have_encap_tunnel == 0) {
have_encap_tunnel = 1;
- for (s = 0; s < MAXVIFS; ++s) {
+ for (s = 0; s < CONFIG_MAXVIFS; ++s) {
multicast_decap_if[s].if_name = "mdecap";
multicast_decap_if[s].if_unit = s;
multicast_decap_if[s].if_family = APPLE_IF_FAM_MDECAP;
return EOPNOTSUPP;
/* Enable promiscuous reception of all IP multicasts from the if */
- s = splnet();
error = if_allmulti(ifp, 1);
- splx(s);
if (error)
return error;
}
- s = splnet();
/* define parameters for the tbf structure */
vifp->v_tbf = v_tbf;
GET_TIME(vifp->v_tbf->tbf_last_pkt_t);
vifp->v_pkt_out = 0;
vifp->v_bytes_in = 0;
vifp->v_bytes_out = 0;
- splx(s);
/* Adjust numvifs up if the vifi is higher than numvifs */
if (numvifs <= vifcp->vifc_vifi) numvifs = vifcp->vifc_vifi + 1;
if (mrtdebug)
log(LOG_DEBUG, "add_vif #%d, lcladdr %lx, %s %lx, thresh %x, rate %d\n",
vifcp->vifc_vifi,
- (u_long)ntohl(vifcp->vifc_lcl_addr.s_addr),
+ (u_int32_t)ntohl(vifcp->vifc_lcl_addr.s_addr),
(vifcp->vifc_flags & VIFF_TUNNEL) ? "rmtaddr" : "mask",
- (u_long)ntohl(vifcp->vifc_rmt_addr.s_addr),
+ (u_int32_t)ntohl(vifcp->vifc_rmt_addr.s_addr),
vifcp->vifc_threshold,
vifcp->vifc_rate_limit);
* Delete a vif from the vif table
*/
static int
-del_vif(vifi)
- vifi_t vifi;
+del_vif(vifi_t vifi)
{
- register struct vif *vifp = &viftable[vifi];
- register struct mbuf *m;
+ struct vif *vifp = &viftable[vifi];
+ struct mbuf *m;
struct ifnet *ifp;
struct ifreq ifr;
- int s;
if (vifi >= numvifs) return EINVAL;
if (vifp->v_lcl_addr.s_addr == 0) return EADDRNOTAVAIL;
- s = splnet();
-
if (!(vifp->v_flags & VIFF_TUNNEL)) {
((struct sockaddr_in *)&(ifr.ifr_addr))->sin_family = AF_INET;
((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr.s_addr = INADDR_ANY;
if (viftable[vifi-1].v_lcl_addr.s_addr != 0) break;
numvifs = vifi;
- splx(s);
-
return 0;
}
* Add an mfc entry
*/
static int
-add_mfc(mfccp)
- struct mfcctl *mfccp;
+add_mfc(struct mfcctl *mfccp)
{
struct mfc *rt;
- u_long hash;
+ u_int32_t hash;
struct rtdetq *rte;
- register u_short nstl;
- int s;
+ u_short nstl;
int i;
MFCFIND(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr, rt);
if (rt) {
if (mrtdebug & DEBUG_MFC)
log(LOG_DEBUG,"add_mfc update o %lx g %lx p %x\n",
- (u_long)ntohl(mfccp->mfcc_origin.s_addr),
- (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
+ (u_int32_t)ntohl(mfccp->mfcc_origin.s_addr),
+ (u_int32_t)ntohl(mfccp->mfcc_mcastgrp.s_addr),
mfccp->mfcc_parent);
- s = splnet();
rt->mfc_parent = mfccp->mfcc_parent;
for (i = 0; i < numvifs; i++)
rt->mfc_ttls[i] = mfccp->mfcc_ttls[i];
- splx(s);
return 0;
}
/*
* Find the entry for which the upcall was made and update
*/
- s = splnet();
hash = MFCHASH(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr);
for (rt = mfctable[hash], nstl = 0; rt; rt = rt->mfc_next) {
if (nstl++)
log(LOG_ERR, "add_mfc %s o %lx g %lx p %x dbx %p\n",
"multiple kernel entries",
- (u_long)ntohl(mfccp->mfcc_origin.s_addr),
- (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
+ (u_int32_t)ntohl(mfccp->mfcc_origin.s_addr),
+ (u_int32_t)ntohl(mfccp->mfcc_mcastgrp.s_addr),
mfccp->mfcc_parent, (void *)rt->mfc_stall);
if (mrtdebug & DEBUG_MFC)
log(LOG_DEBUG,"add_mfc o %lx g %lx p %x dbg %p\n",
- (u_long)ntohl(mfccp->mfcc_origin.s_addr),
- (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
+ (u_int32_t)ntohl(mfccp->mfcc_origin.s_addr),
+ (u_int32_t)ntohl(mfccp->mfcc_mcastgrp.s_addr),
mfccp->mfcc_parent, (void *)rt->mfc_stall);
rt->mfc_origin = mfccp->mfcc_origin;
if (nstl == 0) {
if (mrtdebug & DEBUG_MFC)
log(LOG_DEBUG,"add_mfc no upcall h %lu o %lx g %lx p %x\n",
- hash, (u_long)ntohl(mfccp->mfcc_origin.s_addr),
- (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
+ hash, (u_int32_t)ntohl(mfccp->mfcc_origin.s_addr),
+ (u_int32_t)ntohl(mfccp->mfcc_mcastgrp.s_addr),
mfccp->mfcc_parent);
for (rt = mfctable[hash]; rt != NULL; rt = rt->mfc_next) {
/* no upcall, so make a new entry */
rt = (struct mfc *) _MALLOC(sizeof(*rt), M_MRTABLE, M_NOWAIT);
if (rt == NULL) {
- splx(s);
return ENOBUFS;
}
mfctable[hash] = rt;
}
}
- splx(s);
return 0;
}
/*
* collect delay statistics on the upcalls
*/
-static void collate(t)
-register struct timeval *t;
+static void
+collate(struct timeval *t)
{
- register u_long d;
- register struct timeval tp;
- register u_long delta;
+ u_int32_t d;
+ struct timeval tp;
+ u_int32_t delta;
GET_TIME(tp);
* Delete an mfc entry
*/
static int
-del_mfc(mfccp)
- struct mfcctl *mfccp;
+del_mfc(struct mfcctl *mfccp)
{
struct in_addr origin;
struct in_addr mcastgrp;
struct mfc *rt;
struct mfc **nptr;
- u_long hash;
- int s;
+ u_int32_t hash;
origin = mfccp->mfcc_origin;
mcastgrp = mfccp->mfcc_mcastgrp;
if (mrtdebug & DEBUG_MFC)
log(LOG_DEBUG,"del_mfc orig %lx mcastgrp %lx\n",
- (u_long)ntohl(origin.s_addr), (u_long)ntohl(mcastgrp.s_addr));
-
- s = splnet();
+ (u_int32_t)ntohl(origin.s_addr), (u_int32_t)ntohl(mcastgrp.s_addr));
nptr = &mfctable[hash];
while ((rt = *nptr) != NULL) {
nptr = &rt->mfc_next;
}
if (rt == NULL) {
- splx(s);
return EADDRNOTAVAIL;
}
*nptr = rt->mfc_next;
FREE(rt, M_MRTABLE);
- splx(s);
-
return 0;
}
* Send a message to mrouted on the multicast routing socket
*/
static int
-socket_send(s, mm, src)
- struct socket *s;
- struct mbuf *mm;
- struct sockaddr_in *src;
+socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in *src)
{
socket_lock(s, 1);
if (s) {
#define TUNNEL_LEN 12 /* # bytes of IP option for tunnel encapsulation */
static int
-X_ip_mforward(ip, ifp, m, imo)
- register struct ip *ip;
- struct ifnet *ifp;
- struct mbuf *m;
- struct ip_moptions *imo;
+X_ip_mforward(struct ip *ip, struct ifnet *ifp, struct mbuf *m,
+ struct ip_moptions *imo)
{
- register struct mfc *rt;
- register u_char *ipoptions;
- static struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
+ struct mfc *rt;
+ u_char *ipoptions;
+ static struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET,
+ 0 , {0}, {0,0,0,0,0,0,0,0,} };
static int srctun = 0;
- register struct mbuf *mm;
- int s;
+ struct mbuf *mm;
vifi_t vifi;
struct vif *vifp;
if (mrtdebug & DEBUG_FORWARD)
log(LOG_DEBUG, "ip_mforward: src %lx, dst %lx, ifp %p\n",
- (u_long)ntohl(ip->ip_src.s_addr), (u_long)ntohl(ip->ip_dst.s_addr),
+ (u_int32_t)ntohl(ip->ip_src.s_addr), (u_int32_t)ntohl(ip->ip_dst.s_addr),
(void *)ifp);
if (ip->ip_hl < (IP_HDR_LEN + TUNNEL_LEN) >> 2 ||
if ((srctun++ % 1000) == 0)
log(LOG_ERR,
"ip_mforward: received source-routed packet from %lx\n",
- (u_long)ntohl(ip->ip_src.s_addr));
+ (u_int32_t)ntohl(ip->ip_src.s_addr));
return 1;
}
ip->ip_ttl++; /* compensate for -1 in *_send routines */
if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
vifp = viftable + vifi;
- printf("Sending IPPROTO_RSVP from %lx to %lx on vif %d (%s%s%d)\n",
+ printf("Sending IPPROTO_RSVP from %x to %x on vif %d (%s%s%d)\n",
ntohl(ip->ip_src.s_addr), ntohl(ip->ip_dst.s_addr), vifi,
(vifp->v_flags & VIFF_TUNNEL) ? "tunnel on " : "",
vifp->v_ifp->if_name, vifp->v_ifp->if_unit);
return (ip_mdq(m, ifp, NULL, vifi));
}
if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
- printf("Warning: IPPROTO_RSVP from %lx to %lx without vif option\n",
+ printf("Warning: IPPROTO_RSVP from %x to %x without vif option\n",
ntohl(ip->ip_src.s_addr), ntohl(ip->ip_dst.s_addr));
if(!imo)
printf("In fact, no options were specified at all\n");
/*
* Determine forwarding vifs from the forwarding cache table
*/
- s = splnet();
MFCFIND(ip->ip_src.s_addr, ip->ip_dst.s_addr, rt);
/* Entry exists, so forward if necessary */
if (rt != NULL) {
- splx(s);
return (ip_mdq(m, ifp, rt, -1));
} else {
/*
* send message to routing daemon
*/
- register struct mbuf *mb0;
- register struct rtdetq *rte;
- register u_long hash;
+ struct mbuf *mb0;
+ struct rtdetq *rte;
+ u_int32_t hash;
int hlen = ip->ip_hl << 2;
#if UPCALL_TIMING
struct timeval tp;
mrtstat.mrts_no_route++;
if (mrtdebug & (DEBUG_FORWARD | DEBUG_MFC))
log(LOG_DEBUG, "ip_mforward: no rte s %lx g %lx\n",
- (u_long)ntohl(ip->ip_src.s_addr),
- (u_long)ntohl(ip->ip_dst.s_addr));
+ (u_int32_t)ntohl(ip->ip_src.s_addr),
+ (u_int32_t)ntohl(ip->ip_dst.s_addr));
/*
* Allocate mbufs early so that we don't do extra work if we are
*/
rte = (struct rtdetq *) _MALLOC((sizeof *rte), M_MRTABLE, M_NOWAIT);
if (rte == NULL) {
- splx(s);
return ENOBUFS;
}
mb0 = m_copy(m, 0, M_COPYALL);
mb0 = m_pullup(mb0, hlen);
if (mb0 == NULL) {
FREE(rte, M_MRTABLE);
- splx(s);
return ENOBUFS;
}
if (rt == NULL) {
FREE(rte, M_MRTABLE);
m_freem(mb0);
- splx(s);
return ENOBUFS;
}
/* Make a copy of the header to send to the user level process */
FREE(rte, M_MRTABLE);
m_freem(mb0);
FREE(rt, M_MRTABLE);
- splx(s);
return ENOBUFS;
}
FREE(rte, M_MRTABLE);
m_freem(mb0);
FREE(rt, M_MRTABLE);
- splx(s);
return ENOBUFS;
}
mrtstat.mrts_upq_ovflw++;
FREE(rte, M_MRTABLE);
m_freem(mb0);
- splx(s);
return 0;
}
#endif
rte->next = NULL;
- splx(s);
-
return 0;
}
}
* Clean up the cache entry if upcall is not serviced
*/
static void
-expire_upcalls(void *unused)
+expire_upcalls(__unused void *unused)
{
struct rtdetq *rte;
struct mfc *mfc, **nptr;
int i;
- int s;
-
- s = splnet();
- for (i = 0; i < MFCTBLSIZ; i++) {
+ for (i = 0; i < CONFIG_MFCTBLSIZ; i++) {
if (nexpire[i] == 0)
continue;
nptr = &mfctable[i];
--mfc->mfc_expire == 0) {
if (mrtdebug & DEBUG_EXPIRE)
log(LOG_DEBUG, "expire_upcalls: expiring (%lx %lx)\n",
- (u_long)ntohl(mfc->mfc_origin.s_addr),
- (u_long)ntohl(mfc->mfc_mcastgrp.s_addr));
+ (u_int32_t)ntohl(mfc->mfc_origin.s_addr),
+ (u_int32_t)ntohl(mfc->mfc_mcastgrp.s_addr));
/*
* drop all the packets
* free the mbuf with the pkt, if, timing info
}
}
}
- splx(s);
timeout(expire_upcalls, (caddr_t)NULL, EXPIRE_TIMEOUT);
}
* Packet forwarding routine once entry in the cache is made
*/
static int
-ip_mdq(m, ifp, rt, xmt_vif)
- register struct mbuf *m;
- register struct ifnet *ifp;
- register struct mfc *rt;
- register vifi_t xmt_vif;
+ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt,
+ vifi_t xmt_vif)
{
- register struct ip *ip = mtod(m, struct ip *);
- register vifi_t vifi;
- register struct vif *vifp;
- register int plen = ip->ip_len;
+ struct ip *ip = mtod(m, struct ip *);
+ vifi_t vifi;
+ struct vif *vifp;
+ int plen = ip->ip_len;
/*
* Macro to send packet on vif. Since RSVP packets don't get counted on
struct igmpmsg *im;
int hlen = ip->ip_hl << 2;
struct timeval now;
- register u_long delta;
+ u_int32_t delta;
GET_TIME(now);
* numvifs there,
*/
static int
-X_legal_vif_num(vif)
- int vif;
+X_legal_vif_num(int vif)
{
if (vif >= 0 && vif < numvifs)
return(1);
/*
* Return the local address used by this vif
*/
-static u_long
-X_ip_mcast_src(vifi)
- int vifi;
+static u_int32_t
+X_ip_mcast_src(int vifi)
{
if (vifi >= 0 && vifi < numvifs)
return viftable[vifi].v_lcl_addr.s_addr;
}
#if !defined(MROUTE_LKM) || !MROUTE_LKM
-u_long (*ip_mcast_src)(int) = X_ip_mcast_src;
+u_int32_t (*ip_mcast_src)(int) = X_ip_mcast_src;
#endif
static void
-phyint_send(ip, vifp, m)
- struct ip *ip;
- struct vif *vifp;
- struct mbuf *m;
+phyint_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
{
- register struct mbuf *mb_copy;
- register int hlen = ip->ip_hl << 2;
+ struct mbuf *mb_copy;
+ int hlen = ip->ip_hl << 2;
/*
* Make a new reference to the packet; make sure that
}
static void
-encap_send(ip, vifp, m)
- register struct ip *ip;
- register struct vif *vifp;
- register struct mbuf *m;
+encap_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
{
- register struct mbuf *mb_copy;
- register struct ip *ip_copy;
- register int i, len = ip->ip_len;
+ struct mbuf *mb_copy;
+ struct ip *ip_copy;
+ int i, len = ip->ip_len;
/*
* copy the old packet & pullup its IP header into the
MGETHDR(mb_copy, M_DONTWAIT, MT_HEADER);
if (mb_copy == NULL)
return;
+#if CONFIG_MACF_NET
+ mac_mbuf_label_associate_multicast_encap(m, vifp->v_ifp, mb_copy);
+#endif
mb_copy->m_data += max_linkhdr;
mb_copy->m_len = sizeof(multicast_encap_iphdr);
*/
ip = (struct ip *)((caddr_t)ip_copy + sizeof(multicast_encap_iphdr));
--ip->ip_ttl;
+
+#if BYTE_ORDER != BIG_ENDIAN
HTONS(ip->ip_len);
HTONS(ip->ip_off);
+#endif
+
ip->ip_sum = 0;
mb_copy->m_data += sizeof(multicast_encap_iphdr);
ip->ip_sum = in_cksum(mb_copy, ip->ip_hl << 2);
*/
void
#if MROUTE_LKM
-X_ipip_input(m, iphlen)
+X_ipip_input(struct mbuf *m, int iphlen)
#else
-ipip_input(m, iphlen)
+ipip_input(struct mbuf *m, int iphlen)
#endif
- register struct mbuf *m;
- int iphlen;
{
struct ifnet *ifp = m->m_pkthdr.rcvif;
- register struct ip *ip = mtod(m, struct ip *);
- register int hlen = ip->ip_hl << 2;
- register struct vif *vifp;
+ struct ip *ip = mtod(m, struct ip *);
+ int hlen = ip->ip_hl << 2;
+ struct vif *vifp;
if (!have_encap_tunnel) {
rip_input(m, iphlen);
return;
}
if (ip->ip_src.s_addr != last_encap_src) {
- register struct vif *vife;
+ struct vif *vife;
vifp = viftable;
vife = vifp + numvifs;
m_freem(m);
if (mrtdebug)
log(LOG_DEBUG, "ip_mforward: no tunnel with %lx\n",
- (u_long)ntohl(ip->ip_src.s_addr));
+ (u_int32_t)ntohl(ip->ip_src.s_addr));
return;
}
ifp = vifp->v_ifp;
*/
static void
-tbf_control(vifp, m, ip, p_len)
- register struct vif *vifp;
- register struct mbuf *m;
- register struct ip *ip;
- register u_long p_len;
+tbf_control(struct vif *vifp, struct mbuf *m, struct ip *ip,
+ u_int32_t p_len)
{
- register struct tbf *t = vifp->v_tbf;
+ struct tbf *t = vifp->v_tbf;
if (p_len > MAX_BKT_SIZE) {
/* drop if packet is too large */
* adds a packet to the queue at the interface
*/
static void
-tbf_queue(vifp, m)
- register struct vif *vifp;
- register struct mbuf *m;
+tbf_queue(struct vif *vifp, struct mbuf *m)
{
- register int s = splnet();
- register struct tbf *t = vifp->v_tbf;
+ struct tbf *t = vifp->v_tbf;
if (t->tbf_t == NULL) {
/* Queue was empty */
m->m_act = NULL;
t->tbf_q_len++;
-
- splx(s);
}
* processes the queue at the interface
*/
static void
-tbf_process_q(vifp)
- register struct vif *vifp;
+tbf_process_q(struct vif *vifp)
{
- register struct mbuf *m;
- register int len;
- register int s = splnet();
- register struct tbf *t = vifp->v_tbf;
+ struct mbuf *m;
+ int len;
+ struct tbf *t = vifp->v_tbf;
/* loop through the queue at the interface and send as many packets
* as possible
} else break;
}
- splx(s);
}
static void
-tbf_reprocess_q(xvifp)
- void *xvifp;
+tbf_reprocess_q(void *xvifp)
{
- register struct vif *vifp = xvifp;
+ struct vif *vifp = xvifp;
if (ip_mrouter == NULL) {
return;
* based on the precedence value and the priority
*/
static int
-tbf_dq_sel(vifp, ip)
- register struct vif *vifp;
- register struct ip *ip;
+tbf_dq_sel(struct vif *vifp, struct ip *ip)
{
- register int s = splnet();
- register u_int p;
- register struct mbuf *m, *last;
- register struct mbuf **np;
- register struct tbf *t = vifp->v_tbf;
+ u_int p;
+ struct mbuf *m, *last;
+ struct mbuf **np;
+ struct tbf *t = vifp->v_tbf;
p = priority(vifp, ip);
* we check anyway. */
if (--t->tbf_q_len == 0)
t->tbf_t = NULL;
- splx(s);
mrtstat.mrts_drop_sel++;
return(1);
}
np = &m->m_act;
last = m;
}
- splx(s);
return(0);
}
static void
-tbf_send_packet(vifp, m)
- register struct vif *vifp;
- register struct mbuf *m;
+tbf_send_packet(struct vif *vifp, struct mbuf *m)
{
struct ip_moptions imo;
int error;
static struct route ro;
- int s = splnet();
if (vifp->v_flags & VIFF_TUNNEL) {
/* If tunnel options */
ip_output(m, (struct mbuf *)0, &vifp->v_route,
- IP_FORWARDING, (struct ip_moptions *)0);
+ IP_FORWARDING, (struct ip_moptions *)0, NULL);
} else {
imo.imo_multicast_ifp = vifp->v_ifp;
imo.imo_multicast_ttl = mtod(m, struct ip *)->ip_ttl - 1;
* the loopback interface, thus preventing looping.
*/
error = ip_output(m, (struct mbuf *)0, &ro,
- IP_FORWARDING, &imo);
+ IP_FORWARDING, &imo, NULL);
if (mrtdebug & DEBUG_XMIT)
log(LOG_DEBUG, "phyint_send on vif %d err %d\n",
vifp - viftable, error);
}
- splx(s);
}
/* determine the current time and then
* in milliseconds & update the no. of tokens in the bucket
*/
static void
-tbf_update_tokens(vifp)
- register struct vif *vifp;
+tbf_update_tokens(struct vif *vifp)
{
struct timeval tp;
- register u_long tm;
- register int s = splnet();
- register struct tbf *t = vifp->v_tbf;
+ u_int32_t tm;
+ struct tbf *t = vifp->v_tbf;
GET_TIME(tp);
if (t->tbf_n_tok > MAX_BKT_SIZE)
t->tbf_n_tok = MAX_BKT_SIZE;
-
- splx(s);
}
static int
-priority(vifp, ip)
- register struct vif *vifp;
- register struct ip *ip;
+priority(__unused struct vif *vifp, struct ip *ip)
{
- register int prio;
+ int prio;
/* temporary hack; may add general packet classifier some day */
*/
int
-ip_rsvp_vif_init(so, sopt)
- struct socket *so;
- struct sockopt *sopt;
+ip_rsvp_vif_init(struct socket *so, struct sockopt *sopt)
{
- int error, i, s;
+ int error, i;
if (rsvpdebug)
printf("ip_rsvp_vif_init: so_type = %d, pr_protocol = %d\n",
if (rsvpdebug)
printf("ip_rsvp_vif_init: vif = %d rsvp_on = %d\n", i, rsvp_on);
- s = splnet();
-
/* Check vif. */
if (!legal_vif_num(i)) {
- splx(s);
return EADDRNOTAVAIL;
}
/* Check if socket is available. */
if (viftable[i].v_rsvpd != NULL) {
- splx(s);
return EADDRINUSE;
}
rsvp_on++;
}
- splx(s);
return 0;
}
int
-ip_rsvp_vif_done(so, sopt)
- struct socket *so;
- struct sockopt *sopt;
+ip_rsvp_vif_done(struct socket *so, struct sockopt *sopt)
{
- int error, i, s;
+ int error, i;
if (rsvpdebug)
printf("ip_rsvp_vif_done: so_type = %d, pr_protocol = %d\n",
error = sooptcopyin(sopt, &i, sizeof i, sizeof i);
if (error)
return (error);
-
- s = splnet();
-
+
/* Check vif. */
if (!legal_vif_num(i)) {
- splx(s);
return EADDRNOTAVAIL;
}
rsvp_on--;
}
- splx(s);
return 0;
}
void
-ip_rsvp_force_done(so)
- struct socket *so;
+ip_rsvp_force_done(struct socket *so)
{
int vifi;
- register int s;
/* 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;
- s = splnet();
-
/* The socket may be attached to more than one vif...this
* is perfectly legal.
*/
}
}
- splx(s);
return;
}
void
-rsvp_input(m, iphlen)
- struct mbuf *m;
- int iphlen;
+rsvp_input(struct mbuf *m, int iphlen)
{
int vifi;
- register struct ip *ip = mtod(m, struct ip *);
- static struct sockaddr_in rsvp_src = { sizeof rsvp_src, AF_INET };
- register int s;
+ struct ip *ip = mtod(m, struct ip *);
+ static struct sockaddr_in rsvp_src = { sizeof rsvp_src, AF_INET,
+ 0 , {0}, {0,0,0,0,0,0,0,0,} };
struct ifnet *ifp;
if (rsvpdebug)
return;
}
- s = splnet();
-
if (rsvpdebug)
printf("rsvp_input: check vifs\n");
printf("rsvp_input: No socket defined for vif %d\n",vifi);
m_freem(m);
}
- splx(s);
return;
}
rsvp_src.sin_addr = ip->ip_src;
if (rsvpdebug && m)
- printf("rsvp_input: m->m_len = %d, sbspace() = %ld\n",
+ printf("rsvp_input: m->m_len = %d, sbspace() = %d\n",
m->m_len,sbspace(&(viftable[vifi].v_rsvpd->so_rcv)));
if (socket_send(viftable[vifi].v_rsvpd, m, &rsvp_src) < 0) {
printf("rsvp_input: send packet up\n");
}
- splx(s);
}
#if MROUTE_LKM