Deleted Added
full compact
ip_output.c (167831) ip_output.c (169454)
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 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

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

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 * @(#)ip_output.c 8.3 (Berkeley) 1/21/94
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 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

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

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 * @(#)ip_output.c 8.3 (Berkeley) 1/21/94
30 * $FreeBSD: head/sys/netinet/ip_output.c 167831 2007-03-23 09:43:36Z bms $
30 * $FreeBSD: head/sys/netinet/ip_output.c 169454 2007-05-10 15:58:48Z rwatson $
31 */
32
33#include "opt_ipfw.h"
34#include "opt_ipsec.h"
35#include "opt_mac.h"
36#include "opt_mbuf_stress_test.h"
37
38#include <sys/param.h>

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

102 * IP output. The packet in mbuf chain m contains a skeletal IP
103 * header (with len, off, ttl, proto, tos, src, dst).
104 * The mbuf chain containing the packet will be freed.
105 * The mbuf opt, if present, will not be freed.
106 * In the IP forwarding case, the packet will arrive with options already
107 * inserted, so must have a NULL opt pointer.
108 */
109int
31 */
32
33#include "opt_ipfw.h"
34#include "opt_ipsec.h"
35#include "opt_mac.h"
36#include "opt_mbuf_stress_test.h"
37
38#include <sys/param.h>

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

102 * IP output. The packet in mbuf chain m contains a skeletal IP
103 * header (with len, off, ttl, proto, tos, src, dst).
104 * The mbuf chain containing the packet will be freed.
105 * The mbuf opt, if present, will not be freed.
106 * In the IP forwarding case, the packet will arrive with options already
107 * inserted, so must have a NULL opt pointer.
108 */
109int
110ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro,
111 int flags, struct ip_moptions *imo, struct inpcb *inp)
110ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
111 struct ip_moptions *imo, struct inpcb *inp)
112{
113 struct ip *ip;
114 struct ifnet *ifp = NULL; /* keep compiler happy */
115 struct mbuf *m0;
116 int hlen = sizeof (struct ip);
117 int mtu;
118 int len, error = 0;
119 struct sockaddr_in *dst = NULL; /* keep compiler happy */

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

621 * Return 0 if no error. If error, m_frag may contain a partially built
622 * chain of fragments that should be freed by the caller.
623 *
624 * if_hwassist_flags is the hw offload capabilities (see if_data.ifi_hwassist)
625 * sw_csum contains the delayed checksums flags (e.g., CSUM_DELAY_IP).
626 */
627int
628ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu,
112{
113 struct ip *ip;
114 struct ifnet *ifp = NULL; /* keep compiler happy */
115 struct mbuf *m0;
116 int hlen = sizeof (struct ip);
117 int mtu;
118 int len, error = 0;
119 struct sockaddr_in *dst = NULL; /* keep compiler happy */

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

621 * Return 0 if no error. If error, m_frag may contain a partially built
622 * chain of fragments that should be freed by the caller.
623 *
624 * if_hwassist_flags is the hw offload capabilities (see if_data.ifi_hwassist)
625 * sw_csum contains the delayed checksums flags (e.g., CSUM_DELAY_IP).
626 */
627int
628ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu,
629 u_long if_hwassist_flags, int sw_csum)
629 u_long if_hwassist_flags, int sw_csum)
630{
631 int error = 0;
632 int hlen = ip->ip_hl << 2;
633 int len = (mtu - hlen) & ~7; /* size of payload in each fragment */
634 int off;
635 struct mbuf *m0 = *m_frag; /* the original packet */
636 int firstlen;
637 struct mbuf **mnext;

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

809 }
810 *(u_short *)(m->m_data + offset) = csum;
811}
812
813/*
814 * IP socket option processing.
815 */
816int
630{
631 int error = 0;
632 int hlen = ip->ip_hl << 2;
633 int len = (mtu - hlen) & ~7; /* size of payload in each fragment */
634 int off;
635 struct mbuf *m0 = *m_frag; /* the original packet */
636 int firstlen;
637 struct mbuf **mnext;

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

809 }
810 *(u_short *)(m->m_data + offset) = csum;
811}
812
813/*
814 * IP socket option processing.
815 */
816int
817ip_ctloutput(so, sopt)
818 struct socket *so;
819 struct sockopt *sopt;
817ip_ctloutput(struct socket *so, struct sockopt *sopt)
820{
821 struct inpcb *inp = sotoinpcb(so);
822 int error, optval;
823
824 error = optval = 0;
825 if (sopt->sopt_level != IPPROTO_IP) {
826 return (EINVAL);
827 }

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

1140 * transmission, and one (IP_MULTICAST_TTL) totally duplicates a
1141 * standard option (IP_TTL).
1142 */
1143
1144/*
1145 * following RFC1724 section 3.3, 0.0.0.0/8 is interpreted as interface index.
1146 */
1147static struct ifnet *
818{
819 struct inpcb *inp = sotoinpcb(so);
820 int error, optval;
821
822 error = optval = 0;
823 if (sopt->sopt_level != IPPROTO_IP) {
824 return (EINVAL);
825 }

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

1138 * transmission, and one (IP_MULTICAST_TTL) totally duplicates a
1139 * standard option (IP_TTL).
1140 */
1141
1142/*
1143 * following RFC1724 section 3.3, 0.0.0.0/8 is interpreted as interface index.
1144 */
1145static struct ifnet *
1148ip_multicast_if(a, ifindexp)
1149 struct in_addr *a;
1150 int *ifindexp;
1146ip_multicast_if(struct in_addr *a, int *ifindexp)
1151{
1152 int ifindex;
1153 struct ifnet *ifp;
1154
1155 if (ifindexp)
1156 *ifindexp = 0;
1157 if (ntohl(a->s_addr) >> 24 == 0) {
1158 ifindex = ntohl(a->s_addr) & 0xffffff;

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

1589
1590 return (error);
1591}
1592
1593/*
1594 * Discard the IP multicast options.
1595 */
1596void
1147{
1148 int ifindex;
1149 struct ifnet *ifp;
1150
1151 if (ifindexp)
1152 *ifindexp = 0;
1153 if (ntohl(a->s_addr) >> 24 == 0) {
1154 ifindex = ntohl(a->s_addr) & 0xffffff;

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

1585
1586 return (error);
1587}
1588
1589/*
1590 * Discard the IP multicast options.
1591 */
1592void
1597ip_freemoptions(imo)
1598 register struct ip_moptions *imo;
1593ip_freemoptions(struct ip_moptions *imo)
1599{
1600 register int i;
1601
1602 if (imo != NULL) {
1603 for (i = 0; i < imo->imo_num_memberships; ++i)
1604 in_delmulti(imo->imo_membership[i]);
1605 free(imo->imo_membership, M_IPMOPTS);
1606 free(imo, M_IPMOPTS);
1607 }
1608}
1609
1610/*
1611 * Routine called from ip_output() to loop back a copy of an IP multicast
1612 * packet to the input queue of a specified interface. Note that this
1613 * calls the output routine of the loopback "driver", but with an interface
1614 * pointer that might NOT be a loopback interface -- evil, but easier than
1615 * replicating that code here.
1616 */
1617static void
1594{
1595 register int i;
1596
1597 if (imo != NULL) {
1598 for (i = 0; i < imo->imo_num_memberships; ++i)
1599 in_delmulti(imo->imo_membership[i]);
1600 free(imo->imo_membership, M_IPMOPTS);
1601 free(imo, M_IPMOPTS);
1602 }
1603}
1604
1605/*
1606 * Routine called from ip_output() to loop back a copy of an IP multicast
1607 * packet to the input queue of a specified interface. Note that this
1608 * calls the output routine of the loopback "driver", but with an interface
1609 * pointer that might NOT be a loopback interface -- evil, but easier than
1610 * replicating that code here.
1611 */
1612static void
1618ip_mloopback(ifp, m, dst, hlen)
1619 struct ifnet *ifp;
1620 register struct mbuf *m;
1621 register struct sockaddr_in *dst;
1622 int hlen;
1613ip_mloopback(struct ifnet *ifp, struct mbuf *m, struct sockaddr_in *dst,
1614 int hlen)
1623{
1624 register struct ip *ip;
1625 struct mbuf *copym;
1626
1627 copym = m_copy(m, 0, M_COPYALL);
1628 if (copym != NULL && (copym->m_flags & M_EXT || copym->m_len < hlen))
1629 copym = m_pullup(copym, hlen);
1630 if (copym != NULL) {

--- 44 unchanged lines hidden ---
1615{
1616 register struct ip *ip;
1617 struct mbuf *copym;
1618
1619 copym = m_copy(m, 0, M_COPYALL);
1620 if (copym != NULL && (copym->m_flags & M_EXT || copym->m_len < hlen))
1621 copym = m_pullup(copym, hlen);
1622 if (copym != NULL) {

--- 44 unchanged lines hidden ---