Deleted Added
full compact
ip_mroute.c (166629) ip_mroute.c (166938)
1/*-
2 * Copyright (c) 1989 Stephen Deering
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Stephen Deering of Stanford University.
8 *

--- 38 unchanged lines hidden (view full) ---

47 * Modified by Pavlin Radoslavov, USC/ISI, May 1998, August 1999, October 2000
48 * Modified by Hitoshi Asaeda, WIDE, August 2000
49 * Modified by Pavlin Radoslavov, ICSI, October 2002
50 *
51 * MROUTING Revision: 3.5
52 * and PIM-SMv2 and PIM-DM support, advanced API support,
53 * bandwidth metering and signaling
54 *
1/*-
2 * Copyright (c) 1989 Stephen Deering
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Stephen Deering of Stanford University.
8 *

--- 38 unchanged lines hidden (view full) ---

47 * Modified by Pavlin Radoslavov, USC/ISI, May 1998, August 1999, October 2000
48 * Modified by Hitoshi Asaeda, WIDE, August 2000
49 * Modified by Pavlin Radoslavov, ICSI, October 2002
50 *
51 * MROUTING Revision: 3.5
52 * and PIM-SMv2 and PIM-DM support, advanced API support,
53 * bandwidth metering and signaling
54 *
55 * $FreeBSD: head/sys/netinet/ip_mroute.c 166629 2007-02-10 23:15:28Z bms $
55 * $FreeBSD: head/sys/netinet/ip_mroute.c 166938 2007-02-24 11:38:47Z bms $
56 */
57
56 */
57
58#include "opt_inet.h"
59#include "opt_inet6.h"
58#include "opt_mac.h"
59#include "opt_mrouting.h"
60
61#define _PIM_VT 1
62
63#include <sys/param.h>
64#include <sys/kernel.h>
65#include <sys/lock.h>

--- 21 unchanged lines hidden (view full) ---

87#include <netinet/ip.h>
88#include <netinet/ip_encap.h>
89#include <netinet/ip_mroute.h>
90#include <netinet/ip_var.h>
91#include <netinet/ip_options.h>
92#include <netinet/pim.h>
93#include <netinet/pim_var.h>
94#include <netinet/udp.h>
60#include "opt_mac.h"
61#include "opt_mrouting.h"
62
63#define _PIM_VT 1
64
65#include <sys/param.h>
66#include <sys/kernel.h>
67#include <sys/lock.h>

--- 21 unchanged lines hidden (view full) ---

89#include <netinet/ip.h>
90#include <netinet/ip_encap.h>
91#include <netinet/ip_mroute.h>
92#include <netinet/ip_var.h>
93#include <netinet/ip_options.h>
94#include <netinet/pim.h>
95#include <netinet/pim_var.h>
96#include <netinet/udp.h>
97#ifdef INET6
98#include <netinet/ip6.h>
99#include <netinet6/in6_var.h>
100#include <netinet6/ip6_mroute.h>
101#include <netinet6/ip6_var.h>
102#endif
95#include <machine/in_cksum.h>
96
97#include <security/mac/mac_framework.h>
98
99/*
100 * Control debugging code for rsvp and multicast routing code.
101 * Can only set them with the debugger.
102 */

--- 109 unchanged lines hidden (view full) ---

212 .pr_protocol = IPPROTO_PIM,
213 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
214 .pr_input = pim_input,
215 .pr_output = (pr_output_t*)rip_output,
216 .pr_ctloutput = rip_ctloutput,
217 .pr_usrreqs = &rip_usrreqs
218};
219static const struct encaptab *pim_encap_cookie;
103#include <machine/in_cksum.h>
104
105#include <security/mac/mac_framework.h>
106
107/*
108 * Control debugging code for rsvp and multicast routing code.
109 * Can only set them with the debugger.
110 */

--- 109 unchanged lines hidden (view full) ---

220 .pr_protocol = IPPROTO_PIM,
221 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
222 .pr_input = pim_input,
223 .pr_output = (pr_output_t*)rip_output,
224 .pr_ctloutput = rip_ctloutput,
225 .pr_usrreqs = &rip_usrreqs
226};
227static const struct encaptab *pim_encap_cookie;
228
229#ifdef INET6
230/* ip6_mroute.c glue */
231extern struct in6_protosw in6_pim_protosw;
232static const struct encaptab *pim6_encap_cookie;
233
234extern int X_ip6_mrouter_set(struct socket *, struct sockopt *);
235extern int X_ip6_mrouter_get(struct socket *, struct sockopt *);
236extern int X_ip6_mrouter_done(void);
237extern int X_ip6_mforward(struct ip6_hdr *, struct ifnet *, struct mbuf *);
238extern int X_mrt6_ioctl(int, caddr_t);
239#endif
240
220static int pim_encapcheck(const struct mbuf *, int, int, void *);
221
222/*
223 * Note: the PIM Register encapsulation adds the following in front of a
224 * data packet:
225 *
226 * struct pim_encap_hdr {
227 * struct ip ip;

--- 2504 unchanged lines hidden (view full) ---

2732 /* Keep statistics */
2733 pimstat.pims_snd_registers_msgs++;
2734 pimstat.pims_snd_registers_bytes += len;
2735
2736 return 0;
2737}
2738
2739/*
241static int pim_encapcheck(const struct mbuf *, int, int, void *);
242
243/*
244 * Note: the PIM Register encapsulation adds the following in front of a
245 * data packet:
246 *
247 * struct pim_encap_hdr {
248 * struct ip ip;

--- 2504 unchanged lines hidden (view full) ---

2753 /* Keep statistics */
2754 pimstat.pims_snd_registers_msgs++;
2755 pimstat.pims_snd_registers_bytes += len;
2756
2757 return 0;
2758}
2759
2760/*
2740 * pim_encapcheck() is called by the encap4_input() path at runtime to
2761 * pim_encapcheck() is called by the encap[46]_input() path at runtime to
2741 * determine if a packet is for PIM; allowing PIM to be dynamically loaded
2742 * into the kernel.
2743 */
2744static int
2745pim_encapcheck(const struct mbuf *m, int off, int proto, void *arg)
2746{
2747
2748#ifdef DIAGNOSTIC

--- 241 unchanged lines hidden (view full) ---

2990 * XXX: the outer IP header pkt size of a Register is not adjust to
2991 * reflect the fact that the inner multicast data is truncated.
2992 */
2993 rip_input(m, iphlen);
2994
2995 return;
2996}
2997
2762 * determine if a packet is for PIM; allowing PIM to be dynamically loaded
2763 * into the kernel.
2764 */
2765static int
2766pim_encapcheck(const struct mbuf *m, int off, int proto, void *arg)
2767{
2768
2769#ifdef DIAGNOSTIC

--- 241 unchanged lines hidden (view full) ---

3011 * XXX: the outer IP header pkt size of a Register is not adjust to
3012 * reflect the fact that the inner multicast data is truncated.
3013 */
3014 rip_input(m, iphlen);
3015
3016 return;
3017}
3018
3019/*
3020 * XXX: This is common code for dealing with initialization for both
3021 * the IPv4 and IPv6 multicast forwarding paths. It could do with cleanup.
3022 */
2998static int
2999ip_mroute_modevent(module_t mod, int type, void *unused)
3000{
3001 switch (type) {
3002 case MOD_LOAD:
3003 mtx_init(&mrouter_mtx, "mrouter initialization", NULL, MTX_DEF);
3004 MFC_LOCK_INIT();
3005 VIF_LOCK_INIT();
3006 ip_mrouter_reset();
3007 TUNABLE_ULONG_FETCH("net.inet.pim.squelch_wholepkt",
3008 &pim_squelch_wholepkt);
3023static int
3024ip_mroute_modevent(module_t mod, int type, void *unused)
3025{
3026 switch (type) {
3027 case MOD_LOAD:
3028 mtx_init(&mrouter_mtx, "mrouter initialization", NULL, MTX_DEF);
3029 MFC_LOCK_INIT();
3030 VIF_LOCK_INIT();
3031 ip_mrouter_reset();
3032 TUNABLE_ULONG_FETCH("net.inet.pim.squelch_wholepkt",
3033 &pim_squelch_wholepkt);
3034
3009 pim_encap_cookie = encap_attach_func(AF_INET, IPPROTO_PIM,
3010 pim_encapcheck, &in_pim_protosw, NULL);
3011 if (pim_encap_cookie == NULL) {
3012 printf("ip_mroute: unable to attach pim encap\n");
3013 VIF_LOCK_DESTROY();
3014 MFC_LOCK_DESTROY();
3015 mtx_destroy(&mrouter_mtx);
3016 return (EINVAL);
3017 }
3035 pim_encap_cookie = encap_attach_func(AF_INET, IPPROTO_PIM,
3036 pim_encapcheck, &in_pim_protosw, NULL);
3037 if (pim_encap_cookie == NULL) {
3038 printf("ip_mroute: unable to attach pim encap\n");
3039 VIF_LOCK_DESTROY();
3040 MFC_LOCK_DESTROY();
3041 mtx_destroy(&mrouter_mtx);
3042 return (EINVAL);
3043 }
3044
3045#ifdef INET6
3046 pim6_encap_cookie = encap_attach_func(AF_INET6, IPPROTO_PIM,
3047 pim_encapcheck, (struct protosw *)&in6_pim_protosw, NULL);
3048 if (pim6_encap_cookie == NULL) {
3049 printf("ip_mroute: unable to attach pim6 encap\n");
3050 if (pim_encap_cookie) {
3051 encap_detach(pim_encap_cookie);
3052 pim_encap_cookie = NULL;
3053 }
3054 VIF_LOCK_DESTROY();
3055 MFC_LOCK_DESTROY();
3056 mtx_destroy(&mrouter_mtx);
3057 return (EINVAL);
3058 }
3059#endif
3060
3018 ip_mcast_src = X_ip_mcast_src;
3019 ip_mforward = X_ip_mforward;
3020 ip_mrouter_done = X_ip_mrouter_done;
3021 ip_mrouter_get = X_ip_mrouter_get;
3022 ip_mrouter_set = X_ip_mrouter_set;
3061 ip_mcast_src = X_ip_mcast_src;
3062 ip_mforward = X_ip_mforward;
3063 ip_mrouter_done = X_ip_mrouter_done;
3064 ip_mrouter_get = X_ip_mrouter_get;
3065 ip_mrouter_set = X_ip_mrouter_set;
3066
3067#ifdef INET6
3068 ip6_mforward = X_ip6_mforward;
3069 ip6_mrouter_done = X_ip6_mrouter_done;
3070 ip6_mrouter_get = X_ip6_mrouter_get;
3071 ip6_mrouter_set = X_ip6_mrouter_set;
3072 mrt6_ioctl = X_mrt6_ioctl;
3073#endif
3074
3023 ip_rsvp_force_done = X_ip_rsvp_force_done;
3024 ip_rsvp_vif = X_ip_rsvp_vif;
3075 ip_rsvp_force_done = X_ip_rsvp_force_done;
3076 ip_rsvp_vif = X_ip_rsvp_vif;
3077
3025 legal_vif_num = X_legal_vif_num;
3026 mrt_ioctl = X_mrt_ioctl;
3027 rsvp_input_p = X_rsvp_input;
3028 break;
3029
3030 case MOD_UNLOAD:
3031 /*
3032 * Typically module unload happens after the user-level
3033 * process has shutdown the kernel services (the check
3034 * below insures someone can't just yank the module out
3035 * from under a running process). But if the module is
3036 * just loaded and then unloaded w/o starting up a user
3037 * process we still need to cleanup.
3038 */
3078 legal_vif_num = X_legal_vif_num;
3079 mrt_ioctl = X_mrt_ioctl;
3080 rsvp_input_p = X_rsvp_input;
3081 break;
3082
3083 case MOD_UNLOAD:
3084 /*
3085 * Typically module unload happens after the user-level
3086 * process has shutdown the kernel services (the check
3087 * below insures someone can't just yank the module out
3088 * from under a running process). But if the module is
3089 * just loaded and then unloaded w/o starting up a user
3090 * process we still need to cleanup.
3091 */
3039 if (ip_mrouter)
3092 if (ip_mrouter
3093#ifdef INET6
3094 || ip6_mrouter
3095#endif
3096 )
3040 return EINVAL;
3041
3097 return EINVAL;
3098
3099#ifdef INET6
3100 if (pim6_encap_cookie) {
3101 encap_detach(pim6_encap_cookie);
3102 pim6_encap_cookie = NULL;
3103 }
3104 X_ip6_mrouter_done();
3105 ip6_mforward = NULL;
3106 ip6_mrouter_done = NULL;
3107 ip6_mrouter_get = NULL;
3108 ip6_mrouter_set = NULL;
3109 mrt6_ioctl = NULL;
3110#endif
3111
3042 if (pim_encap_cookie) {
3043 encap_detach(pim_encap_cookie);
3044 pim_encap_cookie = NULL;
3045 }
3112 if (pim_encap_cookie) {
3113 encap_detach(pim_encap_cookie);
3114 pim_encap_cookie = NULL;
3115 }
3046
3047 X_ip_mrouter_done();
3048 ip_mcast_src = NULL;
3049 ip_mforward = NULL;
3050 ip_mrouter_done = NULL;
3051 ip_mrouter_get = NULL;
3052 ip_mrouter_set = NULL;
3116 X_ip_mrouter_done();
3117 ip_mcast_src = NULL;
3118 ip_mforward = NULL;
3119 ip_mrouter_done = NULL;
3120 ip_mrouter_get = NULL;
3121 ip_mrouter_set = NULL;
3122
3053 ip_rsvp_force_done = NULL;
3054 ip_rsvp_vif = NULL;
3123 ip_rsvp_force_done = NULL;
3124 ip_rsvp_vif = NULL;
3125
3055 legal_vif_num = NULL;
3056 mrt_ioctl = NULL;
3057 rsvp_input_p = NULL;
3126 legal_vif_num = NULL;
3127 mrt_ioctl = NULL;
3128 rsvp_input_p = NULL;
3129
3058 VIF_LOCK_DESTROY();
3059 MFC_LOCK_DESTROY();
3060 mtx_destroy(&mrouter_mtx);
3061 break;
3130 VIF_LOCK_DESTROY();
3131 MFC_LOCK_DESTROY();
3132 mtx_destroy(&mrouter_mtx);
3133 break;
3134
3062 default:
3063 return EOPNOTSUPP;
3064 }
3065 return 0;
3066}
3067
3068static moduledata_t ip_mroutemod = {
3069 "ip_mroute",
3070 ip_mroute_modevent,
3071 0
3072};
3073DECLARE_MODULE(ip_mroute, ip_mroutemod, SI_SUB_PSEUDO, SI_ORDER_ANY);
3135 default:
3136 return EOPNOTSUPP;
3137 }
3138 return 0;
3139}
3140
3141static moduledata_t ip_mroutemod = {
3142 "ip_mroute",
3143 ip_mroute_modevent,
3144 0
3145};
3146DECLARE_MODULE(ip_mroute, ip_mroutemod, SI_SUB_PSEUDO, SI_ORDER_ANY);