raw_ip6.c (57535) | raw_ip6.c (62587) |
---|---|
1/* 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * 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 --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/* 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * 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 --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/sys/netinet6/raw_ip6.c 57535 2000-02-27 18:35:10Z shin $ | 29 * $FreeBSD: head/sys/netinet6/raw_ip6.c 62587 2000-07-04 16:35:15Z itojun $ |
30 */ 31 32/* 33 * Copyright (c) 1982, 1986, 1988, 1993 34 * The Regents of the University of California. All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions --- 42 unchanged lines hidden (view full) --- 80 81#include <net/if.h> 82#include <net/route.h> 83#include <net/if_types.h> 84 85#include <netinet/in.h> 86#include <netinet/in_var.h> 87#include <netinet/in_systm.h> | 30 */ 31 32/* 33 * Copyright (c) 1982, 1986, 1988, 1993 34 * The Regents of the University of California. All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions --- 42 unchanged lines hidden (view full) --- 80 81#include <net/if.h> 82#include <net/route.h> 83#include <net/if_types.h> 84 85#include <netinet/in.h> 86#include <netinet/in_var.h> 87#include <netinet/in_systm.h> |
88#include <netinet6/ip6.h> | 88#include |
89#include <netinet6/ip6_var.h> 90#include <netinet6/ip6_mroute.h> | 89#include <netinet6/ip6_var.h> 90#include <netinet6/ip6_mroute.h> |
91#include <netinet6/icmp6.h> | 91#include |
92#include <netinet/in_pcb.h> 93#include <netinet6/in6_pcb.h> 94#include <netinet6/nd6.h> | 92#include <netinet/in_pcb.h> 93#include <netinet6/in6_pcb.h> 94#include <netinet6/nd6.h> |
95#include <netinet6/ip6protosw.h> 96#ifdef ENABLE_DEFAULT_SCOPE 97#include <netinet6/scope6_var.h> 98#endif |
|
95 96#ifdef IPSEC 97#include <netinet6/ipsec.h> 98#include <netinet6/ipsec6.h> 99#endif /*IPSEC*/ 100 101#include <machine/stdarg.h> 102 --- 101 unchanged lines hidden (view full) --- 204 ICMP6_PARAMPROB_NEXTHEADER, 205 prvnxtp - mtod(m, char *)); 206 } 207 ip6stat.ip6s_delivered--; 208 } 209 return IPPROTO_DONE; 210} 211 | 99 100#ifdef IPSEC 101#include <netinet6/ipsec.h> 102#include <netinet6/ipsec6.h> 103#endif /*IPSEC*/ 104 105#include <machine/stdarg.h> 106 --- 101 unchanged lines hidden (view full) --- 208 ICMP6_PARAMPROB_NEXTHEADER, 209 prvnxtp - mtod(m, char *)); 210 } 211 ip6stat.ip6s_delivered--; 212 } 213 return IPPROTO_DONE; 214} 215 |
216void 217rip6_ctlinput(cmd, sa, d) 218 int cmd; 219 struct sockaddr *sa; 220 void *d; 221{ 222 struct sockaddr_in6 sa6; 223 struct ip6_hdr *ip6; 224 struct mbuf *m; 225 int off = 0; 226 void (*notify) __P((struct inpcb *, int)) = in6_rtchange; 227 228 if (sa->sa_family != AF_INET6 || 229 sa->sa_len != sizeof(struct sockaddr_in6)) 230 return; 231 232 if ((unsigned)cmd >= PRC_NCMDS) 233 return; 234 if (PRC_IS_REDIRECT(cmd)) 235 notify = in6_rtchange, d = NULL; 236 else if (cmd == PRC_HOSTDEAD) 237 d = NULL; 238 else if (inet6ctlerrmap[cmd] == 0) 239 return; 240 241 /* if the parameter is from icmp6, decode it. */ 242 if (d != NULL) { 243 struct ip6ctlparam *ip6cp = (struct ip6ctlparam *)d; 244 m = ip6cp->ip6c_m; 245 ip6 = ip6cp->ip6c_ip6; 246 off = ip6cp->ip6c_off; 247 } else { 248 m = NULL; 249 ip6 = NULL; 250 } 251 252 /* translate addresses into internal form */ 253 sa6 = *(struct sockaddr_in6 *)sa; 254 if (IN6_IS_ADDR_LINKLOCAL(&sa6.sin6_addr) && m && m->m_pkthdr.rcvif) 255 sa6.sin6_addr.s6_addr16[1] = htons(m->m_pkthdr.rcvif->if_index); 256 257 if (ip6) { 258 /* 259 * XXX: We assume that when IPV6 is non NULL, 260 * M and OFF are valid. 261 */ 262 struct in6_addr s; 263 264 /* translate addresses into internal form */ 265 memcpy(&s, &ip6->ip6_src, sizeof(s)); 266 if (IN6_IS_ADDR_LINKLOCAL(&s)) 267 s.s6_addr16[1] = htons(m->m_pkthdr.rcvif->if_index); 268 269 (void) in6_pcbnotify(&ripcb, (struct sockaddr *)&sa6, 270 0, &s, 0, cmd, notify); 271 } else 272 (void) in6_pcbnotify(&ripcb, (struct sockaddr *)&sa6, 0, 273 &zeroin6_addr, 0, cmd, notify); 274} 275 |
|
212/* 213 * Generate IPv6 header and pass packet to ip6_output. 214 * Tack on options user may have setup with control call. 215 */ 216int 217#if __STDC__ 218rip6_output(struct mbuf *m, ...) 219#else --- 146 unchanged lines hidden (view full) --- 366 if (!n) 367 goto bad; 368 p = (u_int16_t *)(mtod(n, caddr_t) + off); 369 *p = 0; 370 *p = in6_cksum(m, ip6->ip6_nxt, sizeof(*ip6), plen); 371 } 372 373#ifdef IPSEC | 276/* 277 * Generate IPv6 header and pass packet to ip6_output. 278 * Tack on options user may have setup with control call. 279 */ 280int 281#if __STDC__ 282rip6_output(struct mbuf *m, ...) 283#else --- 146 unchanged lines hidden (view full) --- 430 if (!n) 431 goto bad; 432 p = (u_int16_t *)(mtod(n, caddr_t) + off); 433 *p = 0; 434 *p = in6_cksum(m, ip6->ip6_nxt, sizeof(*ip6), plen); 435 } 436 437#ifdef IPSEC |
374 m->m_pkthdr.rcvif = (struct ifnet *)so; | 438 ipsec_setsocket(m, so); |
375#endif /*IPSEC*/ 376 | 439#endif /*IPSEC*/ 440 |
377 error = ip6_output(m, optp, &in6p->in6p_route, IPV6_SOCKINMRCVIF, | 441 error = ip6_output(m, optp, &in6p->in6p_route, 0, |
378 in6p->in6p_moptions, &oifp); 379 if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) { 380 if (oifp) 381 icmp6_ifoutstat_inc(oifp, type, code); 382 icmp6stat.icp6s_outhist[type]++; 383 } 384 385 goto freectl; --- 152 unchanged lines hidden (view full) --- 538 struct sockaddr_in6 *addr = (struct sockaddr_in6 *)nam; 539 struct ifaddr *ia = NULL; 540 541 if (nam->sa_len != sizeof(*addr)) 542 return EINVAL; 543 544 if (TAILQ_EMPTY(&ifnet) || addr->sin6_family != AF_INET6) 545 return EADDRNOTAVAIL; | 442 in6p->in6p_moptions, &oifp); 443 if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) { 444 if (oifp) 445 icmp6_ifoutstat_inc(oifp, type, code); 446 icmp6stat.icp6s_outhist[type]++; 447 } 448 449 goto freectl; --- 152 unchanged lines hidden (view full) --- 602 struct sockaddr_in6 *addr = (struct sockaddr_in6 *)nam; 603 struct ifaddr *ia = NULL; 604 605 if (nam->sa_len != sizeof(*addr)) 606 return EINVAL; 607 608 if (TAILQ_EMPTY(&ifnet) || addr->sin6_family != AF_INET6) 609 return EADDRNOTAVAIL; |
610#ifdef ENABLE_DEFAULT_SCOPE 611 if (addr->sin6_scope_id == 0) { /* not change if specified */ 612 addr->sin6_scope_id = scope6_addr2default(&addr->sin6_addr); 613 } 614#endif |
|
546 if (!IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr) && 547 (ia = ifa_ifwithaddr((struct sockaddr *)addr)) == 0) 548 return EADDRNOTAVAIL; 549 if (ia && 550 ((struct in6_ifaddr *)ia)->ia6_flags & 551 (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY| 552 IN6_IFF_DETACHED|IN6_IFF_DEPRECATED)) { 553 return(EADDRNOTAVAIL); --- 4 unchanged lines hidden (view full) --- 558 559static int 560rip6_connect(struct socket *so, struct sockaddr *nam, struct proc *p) 561{ 562 struct inpcb *inp = sotoinpcb(so); 563 struct sockaddr_in6 *addr = (struct sockaddr_in6 *)nam; 564 struct in6_addr *in6a = NULL; 565 int error = 0; | 615 if (!IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr) && 616 (ia = ifa_ifwithaddr((struct sockaddr *)addr)) == 0) 617 return EADDRNOTAVAIL; 618 if (ia && 619 ((struct in6_ifaddr *)ia)->ia6_flags & 620 (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY| 621 IN6_IFF_DETACHED|IN6_IFF_DEPRECATED)) { 622 return(EADDRNOTAVAIL); --- 4 unchanged lines hidden (view full) --- 627 628static int 629rip6_connect(struct socket *so, struct sockaddr *nam, struct proc *p) 630{ 631 struct inpcb *inp = sotoinpcb(so); 632 struct sockaddr_in6 *addr = (struct sockaddr_in6 *)nam; 633 struct in6_addr *in6a = NULL; 634 int error = 0; |
635#ifdef ENABLE_DEFAULT_SCOPE 636 struct sockaddr_in6 tmp; 637#endif |
|
566 567 if (nam->sa_len != sizeof(*addr)) 568 return EINVAL; 569 if (TAILQ_EMPTY(&ifnet)) 570 return EADDRNOTAVAIL; 571 if (addr->sin6_family != AF_INET6) 572 return EAFNOSUPPORT; | 638 639 if (nam->sa_len != sizeof(*addr)) 640 return EINVAL; 641 if (TAILQ_EMPTY(&ifnet)) 642 return EADDRNOTAVAIL; 643 if (addr->sin6_family != AF_INET6) 644 return EAFNOSUPPORT; |
573 | 645#ifdef ENABLE_DEFAULT_SCOPE 646 if (addr->sin6_scope_id == 0) { /* not change if specified */ 647 /* avoid overwrites */ 648 tmp = *addr; 649 addr = &tmp; 650 addr->sin6_scope_id = scope6_addr2default(&addr->sin6_addr); 651 } 652#endif |
574 /* Source address selection. XXX: need pcblookup? */ 575 in6a = in6_selectsrc(addr, inp->in6p_outputopts, 576 inp->in6p_moptions, &inp->in6p_route, 577 &inp->in6p_laddr, &error); 578 if (in6a == NULL) 579 return (error ? error : EADDRNOTAVAIL); 580 inp->in6p_laddr = *in6a; 581 inp->in6p_faddr = addr->sin6_addr; --- 11 unchanged lines hidden (view full) --- 593static int 594rip6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, 595 struct mbuf *control, struct proc *p) 596{ 597 struct inpcb *inp = sotoinpcb(so); 598 struct sockaddr_in6 tmp; 599 struct sockaddr_in6 *dst; 600 | 653 /* Source address selection. XXX: need pcblookup? */ 654 in6a = in6_selectsrc(addr, inp->in6p_outputopts, 655 inp->in6p_moptions, &inp->in6p_route, 656 &inp->in6p_laddr, &error); 657 if (in6a == NULL) 658 return (error ? error : EADDRNOTAVAIL); 659 inp->in6p_laddr = *in6a; 660 inp->in6p_faddr = addr->sin6_addr; --- 11 unchanged lines hidden (view full) --- 672static int 673rip6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, 674 struct mbuf *control, struct proc *p) 675{ 676 struct inpcb *inp = sotoinpcb(so); 677 struct sockaddr_in6 tmp; 678 struct sockaddr_in6 *dst; 679 |
680 /* always copy sockaddr to avoid overwrites */ |
|
601 if (so->so_state & SS_ISCONNECTED) { 602 if (nam) { 603 m_freem(m); 604 return EISCONN; 605 } 606 /* XXX */ 607 bzero(&tmp, sizeof(tmp)); 608 tmp.sin6_family = AF_INET6; 609 tmp.sin6_len = sizeof(struct sockaddr_in6); 610 bcopy(&inp->in6p_faddr, &tmp.sin6_addr, 611 sizeof(struct in6_addr)); 612 dst = &tmp; 613 } else { 614 if (nam == NULL) { 615 m_freem(m); 616 return ENOTCONN; 617 } | 681 if (so->so_state & SS_ISCONNECTED) { 682 if (nam) { 683 m_freem(m); 684 return EISCONN; 685 } 686 /* XXX */ 687 bzero(&tmp, sizeof(tmp)); 688 tmp.sin6_family = AF_INET6; 689 tmp.sin6_len = sizeof(struct sockaddr_in6); 690 bcopy(&inp->in6p_faddr, &tmp.sin6_addr, 691 sizeof(struct in6_addr)); 692 dst = &tmp; 693 } else { 694 if (nam == NULL) { 695 m_freem(m); 696 return ENOTCONN; 697 } |
618 dst = (struct sockaddr_in6 *)nam; | 698 tmp = *(struct sockaddr_in6 *)nam; 699 dst = &tmp; |
619 } | 700 } |
701#ifdef ENABLE_DEFAULT_SCOPE 702 if (dst->sin6_scope_id == 0) { /* not change if specified */ 703 dst->sin6_scope_id = scope6_addr2default(&dst->sin6_addr); 704 } 705#endif |
|
620 return rip6_output(m, so, dst, control); 621} 622 623struct pr_usrreqs rip6_usrreqs = { 624 rip6_abort, pru_accept_notsupp, rip6_attach, rip6_bind, rip6_connect, 625 pru_connect2_notsupp, in6_control, rip6_detach, rip6_disconnect, 626 pru_listen_notsupp, in6_setpeeraddr, pru_rcvd_notsupp, 627 pru_rcvoob_notsupp, rip6_send, pru_sense_null, rip6_shutdown, 628 in6_setsockaddr, sosend, soreceive, sopoll 629}; | 706 return rip6_output(m, so, dst, control); 707} 708 709struct pr_usrreqs rip6_usrreqs = { 710 rip6_abort, pru_accept_notsupp, rip6_attach, rip6_bind, rip6_connect, 711 pru_connect2_notsupp, in6_control, rip6_detach, rip6_disconnect, 712 pru_listen_notsupp, in6_setpeeraddr, pru_rcvd_notsupp, 713 pru_rcvoob_notsupp, rip6_send, pru_sense_null, rip6_shutdown, 714 in6_setsockaddr, sosend, soreceive, sopoll 715}; |