Deleted Added
sdiff udiff text old ( 54175 ) new ( 55009 )
full compact
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

--- 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 * @(#)ip_output.c 8.3 (Berkeley) 1/21/94
34 * $FreeBSD: head/sys/netinet/ip_output.c 54175 1999-12-06 00:43:07Z archie $
35 */
36
37#define _IP_VHL
38
39#include "opt_ipfw.h"
40#include "opt_ipdn.h"
41#include "opt_ipdivert.h"
42#include "opt_ipfilter.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/kernel.h>
47#include <sys/malloc.h>
48#include <sys/mbuf.h>
49#include <sys/protosw.h>
50#include <sys/socket.h>
51#include <sys/socketvar.h>
52
53#include <net/if.h>
54#include <net/route.h>
55
56#include <netinet/in.h>
57#include <netinet/in_systm.h>
58#include <netinet/ip.h>
59#include <netinet/in_pcb.h>
60#include <netinet/in_var.h>
61#include <netinet/ip_var.h>
62
63#ifdef vax
64#include <machine/mtpr.h>
65#endif
66#include <machine/in_cksum.h>
67
68static MALLOC_DEFINE(M_IPMOPTS, "ip_moptions", "internet multicast options");
69
70#include <netinet/ip_fw.h>
71
72#ifdef DUMMYNET
73#include <netinet/ip_dummynet.h>
74#endif
75
76#ifdef IPFIREWALL_FORWARD_DEBUG
77#define print_ip(a) printf("%ld.%ld.%ld.%ld",(ntohl(a.s_addr)>>24)&0xFF,\

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

118 struct ip *ip, *mhip;
119 struct ifnet *ifp;
120 struct mbuf *m = m0;
121 int hlen = sizeof (struct ip);
122 int len, off, error = 0;
123 struct sockaddr_in *dst;
124 struct in_ifaddr *ia;
125 int isbroadcast;
126 u_int16_t divert_cookie; /* firewall cookie */
127#ifdef IPFIREWALL_FORWARD
128 int fwd_rewrite_src = 0;
129#endif
130 struct ip_fw_chain *rule = NULL;
131
132#ifdef IPDIVERT
133 /* Get and reset firewall cookie */
134 divert_cookie = ip_divert_cookie;
135 ip_divert_cookie = 0;
136#else
137 divert_cookie = 0;
138#endif
139
140#if defined(IPFIREWALL) && defined(DUMMYNET)
141 /*
142 * dummynet packet are prepended a vestigial mbuf with
143 * m_type = MT_DUMMYNET and m_data pointing to the matching
144 * rule.
145 */
146 if (m->m_type == MT_DUMMYNET) {
147 /*
148 * the packet was already tagged, so part of the
149 * processing was already done, and we need to go down.
150 * opt, flags and imo have already been used, and now
151 * they are used to hold ifp, dst and NULL, respectively.
152 */
153 rule = (struct ip_fw_chain *)(m->m_data) ;
154 m0 = m = m->m_next ;
155 ip = mtod(m, struct ip *);
156 dst = (struct sockaddr_in *)flags ;
157 ifp = (struct ifnet *)opt;
158 hlen = IP_VHL_HL(ip->ip_vhl) << 2 ;
159 opt = NULL ;
160 flags = 0 ; /* XXX is this correct ? */
161 goto sendit;
162 } else
163 rule = NULL ;
164#endif
165
166#ifdef DIAGNOSTIC
167 if ((m->m_flags & M_PKTHDR) == 0)
168 panic("ip_output no HDR");

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

450 * pass the pkt to dummynet. Need to include
451 * pipe number, m, ifp, ro, dst because these are
452 * not recomputed in the next pass.
453 * All other parameters have been already used and
454 * so they are not needed anymore.
455 * XXX note: if the ifp or ro entry are deleted
456 * while a pkt is in dummynet, we are in trouble!
457 */
458 dummynet_io(off & 0xffff, DN_TO_IP_OUT, m,ifp,ro,dst,rule);
459 goto done;
460 }
461#endif
462#ifdef IPDIVERT
463 if (off != 0 && (off & IP_FW_PORT_DYNT_FLAG) == 0) {
464 struct mbuf *clone = NULL;
465
466 /* Clone packet if we're doing a 'tee' */

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

592 * we have to drop the pkt
593 */
594 m_freem(m);
595 error = EACCES; /* not sure this is the right error msg */
596 goto done;
597 }
598
599pass:
600 /*
601 * If small enough for interface, can just send directly.
602 */
603 if ((u_short)ip->ip_len <= ifp->if_mtu) {
604 ip->ip_len = htons((u_short)ip->ip_len);
605 ip->ip_off = htons((u_short)ip->ip_off);
606 ip->ip_sum = 0;
607 if (ip->ip_vhl == IP_VHL_BORING) {

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

719 else
720 m_freem(m);
721 }
722
723 if (error == 0)
724 ipstat.ips_fragmented++;
725 }
726done:
727 return (error);
728bad:
729 m_freem(m0);
730 goto done;
731}
732
733/*
734 * Insert IP options into preformed packet.

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

863 }
864
865 case IP_TOS:
866 case IP_TTL:
867 case IP_RECVOPTS:
868 case IP_RECVRETOPTS:
869 case IP_RECVDSTADDR:
870 case IP_RECVIF:
871 error = sooptcopyin(sopt, &optval, sizeof optval,
872 sizeof optval);
873 if (error)
874 break;
875
876 switch (sopt->sopt_name) {
877 case IP_TOS:
878 inp->inp_ip_tos = optval;

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

897
898 case IP_RECVDSTADDR:
899 OPTSET(INP_RECVDSTADDR);
900 break;
901
902 case IP_RECVIF:
903 OPTSET(INP_RECVIF);
904 break;
905 }
906 break;
907#undef OPTSET
908
909 case IP_MULTICAST_IF:
910 case IP_MULTICAST_VIF:
911 case IP_MULTICAST_TTL:
912 case IP_MULTICAST_LOOP:

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

938 break;
939
940 default:
941 error = EINVAL;
942 break;
943 }
944 break;
945
946 default:
947 error = ENOPROTOOPT;
948 break;
949 }
950 break;
951
952 case SOPT_GET:
953 switch (sopt->sopt_name) {

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

964
965 case IP_TOS:
966 case IP_TTL:
967 case IP_RECVOPTS:
968 case IP_RECVRETOPTS:
969 case IP_RECVDSTADDR:
970 case IP_RECVIF:
971 case IP_PORTRANGE:
972 switch (sopt->sopt_name) {
973
974 case IP_TOS:
975 optval = inp->inp_ip_tos;
976 break;
977
978 case IP_TTL:
979 optval = inp->inp_ip_ttl;

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

1000 case IP_PORTRANGE:
1001 if (inp->inp_flags & INP_HIGHPORT)
1002 optval = IP_PORTRANGE_HIGH;
1003 else if (inp->inp_flags & INP_LOWPORT)
1004 optval = IP_PORTRANGE_LOW;
1005 else
1006 optval = 0;
1007 break;
1008 }
1009 error = sooptcopyout(sopt, &optval, sizeof optval);
1010 break;
1011
1012 case IP_MULTICAST_IF:
1013 case IP_MULTICAST_VIF:
1014 case IP_MULTICAST_TTL:
1015 case IP_MULTICAST_LOOP:
1016 case IP_ADD_MEMBERSHIP:
1017 case IP_DROP_MEMBERSHIP:
1018 error = ip_getmoptions(sopt, inp->inp_moptions);
1019 break;
1020
1021 default:
1022 error = ENOPROTOOPT;
1023 break;
1024 }
1025 break;
1026 }
1027 return (error);
1028}

--- 543 unchanged lines hidden ---