Skip to content

Commit 9e295a2

Browse files
Bill JoyBill Joy
authored andcommitted
first listing
SCCS-vsn: sys/vax/if/if_en.c 4.6 SCCS-vsn: sys/netinet/in.h 4.2 SCCS-vsn: sys/netinet/ip.h 1.6 SCCS-vsn: sys/netinet/ip_icmp.c 4.2 SCCS-vsn: sys/netinet/ip_input.c 1.12 SCCS-vsn: sys/netinet/ip_output.c 1.11 SCCS-vsn: sys/netinet/tcp.h 1.14 SCCS-vsn: sys/netinet/tcp_input.c 1.21 SCCS-vsn: sys/netinet/tcp_output.c 4.10 SCCS-vsn: sys/netinet/udp_usrreq.c 4.2
1 parent eb8a0e4 commit 9e295a2

File tree

10 files changed

+307
-439
lines changed

10 files changed

+307
-439
lines changed

usr/src/sys/netinet/in.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* in.h 4.1 81/11/07 */
1+
/* in.h 4.2 81/11/08 */
22

33
/*
44
* Constants and structures defined by the internet system,
@@ -8,6 +8,7 @@
88
/*
99
* Protocols
1010
*/
11+
#define IPPROTO_RAW -1
1112
#define IPPROTO_ICMP 1 /* control message protocol */
1213
#define IPPROTO_GG 2 /* gateway^2 (deprecated) */
1314
#define IPPROTO_TCP 6 /* tcp */
@@ -49,7 +50,7 @@
4950
/*
5051
* Internet address (old style... should be updated)
5152
*/
52-
struct socket { /* should be called inet_addr */
53+
struct ip_addr {
5354
union {
5455
struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
5556
struct { u_short s_w1,s_w2; } S_un_w;

usr/src/sys/netinet/ip.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* ip.h 1.5 81/10/29 */
1+
/* ip.h 1.6 81/11/08 */
22

33
/*
44
* Definitions for internet protocol version 4.
@@ -32,13 +32,13 @@ struct ip {
3232
u_char ip_p; /* protocol */
3333
u_short ip_sum; /* checksum */
3434
union {
35-
struct socket ip_s; /* source address */
35+
struct ip_addr ip_s; /* source address */
3636
struct ip *ip_nxt; /* next fragment */
3737
} I_sun;
3838
#define ip_src I_sun.ip_s
3939
#define ip_next I_sun.ip_nxt
4040
union {
41-
struct socket ip_d; /* destination address */
41+
struct ip_addr ip_d; /* destination address */
4242
struct ip *ip_prv; /* prev fragment */
4343
} I_dun;
4444
#define ip_dst I_dun.ip_d
@@ -79,7 +79,7 @@ struct ip_timestamp {
7979
union {
8080
n_long ipt_time[1];
8181
struct ipt_ta {
82-
struct socket ipt_addr;
82+
struct ip_addr ipt_addr;
8383
n_long ipt_time;
8484
} ipt_ta[1];
8585
}
@@ -111,7 +111,7 @@ struct ipq {
111111
u_char ipq_p; /* protocol of this fragment */
112112
u_short ipq_id; /* sequence id for reassembly */
113113
struct ip *ipq_next,*ipq_prev; /* to ip headers of fragments */
114-
struct socket ipq_src,ipq_dst;
114+
struct ip_addr ipq_src,ipq_dst;
115115
};
116116

117117
/*

usr/src/sys/netinet/ip_icmp.c

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
/* ip_icmp.c 4.1 81/11/07 */
1+
/* ip_icmp.c 4.2 81/11/08 */
22

33
#include "../h/param.h"
44
#include "../h/mbuf.h"
5-
#include "../inet/inet.h"
6-
#include "../inet/inet_systm.h"
7-
#include "../inet/ip.h"
5+
#include "../h/inaddr.h"
6+
#include "../net/inet.h"
7+
#include "../net/inet_systm.h"
8+
#include "../net/ip.h"
9+
#include "../net/ip_icmp.h"
810

911
/*
1012
* ICMP routines: error generation, receive packet processing, and
@@ -20,7 +22,7 @@ icmp_error(oip, type, code)
2022
int type;
2123
{
2224
int oiplen = oip->ip_hl << 2;
23-
struct icmp *icp = (struct icp *)((int)oip + oiplen);
25+
struct icmp *icp = (struct icmp *)((int)oip + oiplen);
2426
struct mbuf *m;
2527
struct ip *nip;
2628

@@ -47,17 +49,17 @@ icmp_error(oip, type, code)
4749
icp->icmp_pptr = code;
4850
} else
4951
icp->icmp_code = code;
50-
bcopy((caddr_t)oip, (caddr_t)&icp->icmp_ip.icmp_ip, oiplen + 8);
52+
bcopy((caddr_t)oip, (caddr_t)&icp->icmp_ip, oiplen + 8);
5153

5254
/*
5355
* Now prepend an IP header and reflect this packet back to
5456
* the source.
5557
*/
5658
m->m_off -= sizeof (struct ip);
5759
m->m_len += sizeof (struct ip);
58-
nip = (struct ip *)mtod(m);
59-
*nip = *ip;
60-
icmp_reflect(ip);
60+
nip = (struct ip *)mtod(m, struct ip *);
61+
*nip = *oip;
62+
icmp_reflect(nip);
6163

6264
/*
6365
* Discard mbufs of original datagram
@@ -67,15 +69,16 @@ icmp_error(oip, type, code)
6769
}
6870

6971
/*
70-
* Processor a received ICMP message.
72+
* Process a received ICMP message.
7173
*/
7274
icmp_input(m)
7375
struct mbuf *m;
7476
{
75-
int hlen = ip->ip_hl << 2;
76-
register struct ip *ip = (struct ip *)mtod(m);
7777
register struct icmp *icp;
78+
register struct ip *ip = mtod(m, struct ip *);
79+
int hlen = ip->ip_hl << 2;
7880
int icmplen = ip->ip_len - hlen;
81+
int i;
7982

8083
/*
8184
* Locate icmp structure in mbuf, and check
@@ -84,16 +87,16 @@ icmp_input(m)
8487
m->m_len -= hlen;
8588
m->m_off += hlen;
8689
/* need routine to make sure header is in this mbuf here */
87-
icp = (struct icmp *)mtod(m);
90+
icp = (struct icmp *)mtod(m, struct icmp *);
8891
i = icp->icmp_cksum;
8992
icp->icmp_cksum = 0;
90-
if (i != cksum(m, icmplen) || icmplen < ICMP_MINLEN)
91-
goto bad;
93+
if (i != inet_cksum(m, icmplen) || icmplen < ICMP_MINLEN)
94+
goto free;
9295

9396
/*
9497
* Message type specific processing.
9598
*/
96-
switch (ipc->icmp_type) {
99+
switch (icp->icmp_type) {
97100

98101
case ICMP_UNREACH:
99102
case ICMP_TIMXCEED:
@@ -104,20 +107,20 @@ icmp_input(m)
104107
* Problem with previous datagram; advise
105108
* higher level routines.
106109
*/
107-
if (icmplen < ICMP_MINADVLEN || icmplen < ICMP_ADVLEN(ipc))
108-
goto drop;
109-
icmp_advise(ip, ipc);
110+
if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp))
111+
goto free;
112+
icmp_advise(ip, icp);
110113
goto free;
111114

112115
case ICMP_ECHO:
113116
icp->icmp_type = ICMP_ECHOREPLY;
114117
goto reflect;
115118

116119
case ICMP_TSTAMP:
117-
if (icmplen < ICMP_MINLEN + sizeof ())
118-
goto bad;
120+
if (icmplen < ICMP_TSLEN)
121+
goto free;
119122
icp->icmp_type = ICMP_TSTAMPREPLY;
120-
millitime(&icp->icmp_rtime);
123+
ip_time(&icp->icmp_rtime);
121124
icp->icmp_ttime = icp->icmp_rtime; /* bogus, do later! */
122125
goto reflect;
123126

@@ -128,8 +131,8 @@ icmp_input(m)
128131
case ICMP_ECHOREPLY:
129132
case ICMP_TSTAMPREPLY:
130133
case ICMP_IREQREPLY:
131-
if (icmplen < ICMP_MINADVLEN || icmplen < ICMP_ADVLEN(ipc))
132-
goto drop;
134+
if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp))
135+
goto free;
133136
icmp_gotreply(icp);
134137
goto free;
135138

@@ -148,29 +151,27 @@ icmp_input(m)
148151
icmp_reflect(ip)
149152
struct ip *ip;
150153
{
151-
struct inet_addr t;
154+
struct ip_addr t;
152155

156+
t = ip->ip_src; ip->ip_dst = ip->ip_src; ip->ip_src = t;
153157
/*
154158
* This is a little naive... do we have to munge the options
155159
* to reverse source routing?
156160
*/
157-
t = ip->ip_src.s_addr;
158-
ip->ip_dst.s_addr = ip->ip_src.d_addr;
159-
ip->ip_src.d_addr = t;
160161
icmp_send(ip);
161162
}
162163

163164
/*
164165
* Send an icmp packet back to the ip level, after
165166
* supplying a checksum.
166167
*/
167-
icmp_send(ip, ipc)
168+
icmp_send(ip, icp)
168169
struct ip *ip;
169-
struct icmp *ipc;
170+
struct icmp *icp;
170171
{
171172

172-
ipc->ipc_cksum = 0;
173-
ipc->ipc_cksum = cksum(m, impclen);
173+
icp->icmp_cksum = 0;
174+
icp->icmp_inet_cksum = cksum(dtom(ip), 0); /* ### */
174175
/* what about ttl? */
175176
ip_output(ip);
176177
}
@@ -183,22 +184,9 @@ icmp_advise(ip, icp)
183184
struct ip *ip;
184185
struct icmp *icp;
185186
{
186-
int (*f)(), tcp_advise(), udp_advise(), raw_advise();
187-
188-
switch (ip->ip_p) {
189-
case IPPROTO_TCP:
190-
f = tcp_advise;
191-
break;
192187

193-
case IPPROTO_UDP:
194-
f = udp_advise;
195-
break;
196-
197-
default:
198-
f = raw_advise;
199-
break;
200-
}
201-
(*f)(ip, icp);
188+
/* pass through protocol specific switch */
189+
/* (*f)(ip, icp); */
202190
}
203191

204192
/*
@@ -211,3 +199,13 @@ icmp_gotreply(icp)
211199
{
212200

213201
}
202+
203+
icmp_drain()
204+
{
205+
206+
}
207+
208+
ip_time()
209+
{
210+
211+
}

0 commit comments

Comments
 (0)