Deleted Added
full compact
raw_ip.c (36079) raw_ip.c (38482)
1/*
2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95
1/*
2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95
34 * $Id: raw_ip.c,v 1.53 1998/03/28 10:18:24 bde Exp $
34 * $Id: raw_ip.c,v 1.54 1998/05/15 20:11:34 wollman Exp $
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/malloc.h>
41#include <sys/mbuf.h>
42#include <sys/proc.h>

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

220 return (ip_output(m, inp->inp_options, &inp->inp_route, flags,
221 inp->inp_moptions));
222}
223
224/*
225 * Raw IP socket option processing.
226 */
227int
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/malloc.h>
41#include <sys/mbuf.h>
42#include <sys/proc.h>

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

220 return (ip_output(m, inp->inp_options, &inp->inp_route, flags,
221 inp->inp_moptions));
222}
223
224/*
225 * Raw IP socket option processing.
226 */
227int
228rip_ctloutput(op, so, level, optname, m, p)
229 int op;
228rip_ctloutput(so, sopt)
230 struct socket *so;
229 struct socket *so;
231 int level, optname;
232 struct mbuf **m;
233 struct proc *p;
230 struct sockopt *sopt;
234{
231{
235 register struct inpcb *inp = sotoinpcb(so);
236 register int error;
232 struct inpcb *inp = sotoinpcb(so);
233 int error, optval;
237
234
238 if (level != IPPROTO_IP) {
239 if (op == PRCO_SETOPT && *m)
240 (void)m_free(*m);
235 if (sopt->sopt_level != IPPROTO_IP)
241 return (EINVAL);
236 return (EINVAL);
242 }
243
237
244 switch (optname) {
238 error = 0;
245
239
246 case IP_HDRINCL:
247 error = 0;
248 if (op == PRCO_SETOPT) {
249 if (m == 0 || *m == 0 || (*m)->m_len < sizeof (int))
250 error = EINVAL;
251 else if (*mtod(*m, int *))
240 switch (sopt->sopt_dir) {
241 case SOPT_GET:
242 switch (sopt->sopt_name) {
243 case IP_HDRINCL:
244 optval = inp->inp_flags & INP_HDRINCL;
245 error = sooptcopyout(sopt, &optval, sizeof optval);
246 break;
247
248#ifdef COMPAT_IPFW
249 case IP_FW_GET:
250 if (ip_fw_ctl_ptr == 0)
251 error = ENOPROTOOPT;
252 else
253 error = ip_fw_ctl_ptr(sopt);
254 break;
255
256 case IP_NAT:
257 if (ip_nat_ctl_ptr == 0)
258 error = ENOPROTOOPT;
259 else
260 error = ip_nat_ctl_ptr(sopt);
261 break;
262#endif /* COMPAT_IPFW */
263
264 case MRT_INIT:
265 case MRT_DONE:
266 case MRT_ADD_VIF:
267 case MRT_DEL_VIF:
268 case MRT_ADD_MFC:
269 case MRT_DEL_MFC:
270 case MRT_VERSION:
271 case MRT_ASSERT:
272 error = ip_mrouter_get(so, sopt);
273 break;
274
275 default:
276 error = ip_ctloutput(so, sopt);
277 break;
278 }
279 break;
280
281 case SOPT_SET:
282 switch (sopt->sopt_name) {
283 case IP_HDRINCL:
284 error = sooptcopyin(sopt, &optval, sizeof optval,
285 sizeof optval);
286 if (error)
287 break;
288 if (optval)
252 inp->inp_flags |= INP_HDRINCL;
253 else
254 inp->inp_flags &= ~INP_HDRINCL;
289 inp->inp_flags |= INP_HDRINCL;
290 else
291 inp->inp_flags &= ~INP_HDRINCL;
255 if (*m)
256 (void)m_free(*m);
257 } else {
258 *m = m_get(M_WAIT, MT_SOOPTS);
259 (*m)->m_len = sizeof (int);
260 *mtod(*m, int *) = inp->inp_flags & INP_HDRINCL;
261 }
262 return (error);
292 break;
263
264#ifdef COMPAT_IPFW
293
294#ifdef COMPAT_IPFW
265 case IP_FW_GET:
266 if (ip_fw_ctl_ptr == NULL || op == PRCO_SETOPT) {
267 if (*m) (void)m_free(*m);
268 return(EINVAL);
269 }
270 return (*ip_fw_ctl_ptr)(optname, m);
295 case IP_FW_ADD:
296 case IP_FW_DEL:
297 case IP_FW_FLUSH:
298 case IP_FW_ZERO:
299 if (ip_fw_ctl_ptr == 0)
300 error = ENOPROTOOPT;
301 else
302 error = ip_fw_ctl_ptr(sopt);
303 break;
271
304
272 case IP_FW_ADD:
273 case IP_FW_DEL:
274 case IP_FW_FLUSH:
275 case IP_FW_ZERO:
276 if (ip_fw_ctl_ptr == NULL || op != PRCO_SETOPT) {
277 if (*m) (void)m_free(*m);
278 return(EINVAL);
279 }
280 return (*ip_fw_ctl_ptr)(optname, m);
305 case IP_NAT:
306 if (ip_nat_ctl_ptr == 0)
307 error = ENOPROTOOPT;
308 else
309 error = ip_nat_ctl_ptr(sopt);
310 break;
311#endif /* COMPAT_IPFW */
281
312
282 case IP_NAT:
283 if (ip_nat_ctl_ptr == NULL) {
284 if (*m) (void)m_free(*m);
285 return(EINVAL);
286 }
287 return (*ip_nat_ctl_ptr)(op, m);
313 case IP_RSVP_ON:
314 error = ip_rsvp_init(so);
315 break;
288
316
289#endif
290 case IP_RSVP_ON:
291 return ip_rsvp_init(so);
292 break;
317 case IP_RSVP_OFF:
318 error = ip_rsvp_done();
319 break;
293
320
294 case IP_RSVP_OFF:
295 return ip_rsvp_done();
296 break;
321 /* XXX - should be combined */
322 case IP_RSVP_VIF_ON:
323 error = ip_rsvp_vif_init(so, sopt);
324 break;
325
326 case IP_RSVP_VIF_OFF:
327 error = ip_rsvp_vif_done(so, sopt);
328 break;
297
329
298 case IP_RSVP_VIF_ON:
299 return ip_rsvp_vif_init(so, *m);
330 case MRT_INIT:
331 case MRT_DONE:
332 case MRT_ADD_VIF:
333 case MRT_DEL_VIF:
334 case MRT_ADD_MFC:
335 case MRT_DEL_MFC:
336 case MRT_VERSION:
337 case MRT_ASSERT:
338 error = ip_mrouter_set(so, sopt);
339 break;
300
340
301 case IP_RSVP_VIF_OFF:
302 return ip_rsvp_vif_done(so, *m);
303
304 case MRT_INIT:
305 case MRT_DONE:
306 case MRT_ADD_VIF:
307 case MRT_DEL_VIF:
308 case MRT_ADD_MFC:
309 case MRT_DEL_MFC:
310 case MRT_VERSION:
311 case MRT_ASSERT:
312 if (op == PRCO_SETOPT) {
313 error = ip_mrouter_set(optname, so, *m);
314 if (*m)
315 (void)m_free(*m);
316 } else if (op == PRCO_GETOPT) {
317 error = ip_mrouter_get(optname, so, m);
318 } else
319 error = EINVAL;
320 return (error);
341 default:
342 error = ip_ctloutput(so, sopt);
343 break;
344 }
345 break;
321 }
346 }
322 return (ip_ctloutput(op, so, level, optname, m, p));
347
348 return (error);
323}
324
325/*
326 * This function exists solely to receive the PRC_IFDOWN messages which
327 * are sent by if_down(). It looks for an ifaddr whose ifa_addr is sa,
328 * and calls in_ifadown() to remove all routes corresponding to that address.
329 * It also receives the PRC_IFUP messages from if_up() and reinstalls the
330 * interface routes.

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

335 struct sockaddr *sa;
336 void *vip;
337{
338 struct in_ifaddr *ia;
339 struct ifnet *ifp;
340 int err;
341 int flags;
342
349}
350
351/*
352 * This function exists solely to receive the PRC_IFDOWN messages which
353 * are sent by if_down(). It looks for an ifaddr whose ifa_addr is sa,
354 * and calls in_ifadown() to remove all routes corresponding to that address.
355 * It also receives the PRC_IFUP messages from if_up() and reinstalls the
356 * interface routes.

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

361 struct sockaddr *sa;
362 void *vip;
363{
364 struct in_ifaddr *ia;
365 struct ifnet *ifp;
366 int err;
367 int flags;
368
343 switch(cmd) {
369 switch (cmd) {
344 case PRC_IFDOWN:
345 for (ia = in_ifaddrhead.tqh_first; ia;
346 ia = ia->ia_link.tqe_next) {
347 if (ia->ia_ifa.ifa_addr == sa
348 && (ia->ia_flags & IFA_ROUTE)) {
349 /*
350 * in_ifscrub kills the interface route.
351 */

--- 259 unchanged lines hidden ---
370 case PRC_IFDOWN:
371 for (ia = in_ifaddrhead.tqh_first; ia;
372 ia = ia->ia_link.tqe_next) {
373 if (ia->ia_ifa.ifa_addr == sa
374 && (ia->ia_flags & IFA_ROUTE)) {
375 /*
376 * in_ifscrub kills the interface route.
377 */

--- 259 unchanged lines hidden ---