From e30177e024f908601b4242d6de6450986af95044 Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Thu, 14 Sep 2000 14:42:04 +0000 Subject: [PATCH] Follow BSD/OS and NetBSD, keep the ip_id field in network order all the time. Requested by: wollman --- share/man/man4/ip.4 | 14 +------------- sys/net/bridge.c | 2 -- sys/netinet/ip_auth.c | 2 +- sys/netinet/ip_divert.c | 1 - sys/netinet/ip_fil.c | 2 ++ sys/netinet/ip_icmp.c | 1 - sys/netinet/ip_input.c | 4 ---- sys/netinet/ip_mroute.c | 3 +-- sys/netinet/ip_output.c | 10 +--------- sys/netinet/raw_ip.c | 2 +- sys/netinet6/ah_input.c | 2 -- 11 files changed, 7 insertions(+), 36 deletions(-) diff --git a/share/man/man4/ip.4 b/share/man/man4/ip.4 index 593473bf5b78..491da48be881 100644 --- a/share/man/man4/ip.4 +++ b/share/man/man4/ip.4 @@ -32,7 +32,7 @@ .\" @(#)ip.4 8.2 (Berkeley) 11/30/93 .\" $FreeBSD$ .\" -.Dd September 1, 2000 +.Dd November 30, 1993 .Dt IP 4 .Os BSD 4.2 .Sh NAME @@ -368,10 +368,6 @@ ip->ip_off = offset; If the header source address is set to .Dv INADDR_ANY, the kernel will choose an appropriate address. -.Pp -The header identification field -.Dq Li ip_id -is expected in host byte order. .Sh DIAGNOSTICS A socket operation may fail with one of the following errors returned: .Bl -tag -width [EADDRNOTAVAIL] @@ -420,11 +416,3 @@ The .Nm protocol appeared in .Bx 4.2 . -.Pp -If the -.Dv IP_HDRINCL -option is in use, -.Fx 4.2 -and above expect the -.Dq Li ip_id -field in host byte order. diff --git a/sys/net/bridge.c b/sys/net/bridge.c index ec9aada88ec3..7827a0c18f41 100644 --- a/sys/net/bridge.c +++ b/sys/net/bridge.c @@ -718,7 +718,6 @@ bdg_forward(struct mbuf **m0, struct ether_header *const eh, struct ifnet *dst) */ ip = mtod(m, struct ip *); NTOHS(ip->ip_len); - NTOHS(ip->ip_id); NTOHS(ip->ip_off); /* @@ -744,7 +743,6 @@ bdg_forward(struct mbuf **m0, struct ether_header *const eh, struct ifnet *dst) * Then, if canfree==1, also restore *m0. */ HTONS(ip->ip_len); - HTONS(ip->ip_id); HTONS(ip->ip_off); if (canfree) /* m was a reference to *m0, so update *m0 */ *m0 = m ; diff --git a/sys/netinet/ip_auth.c b/sys/netinet/ip_auth.c index ff728253ea48..4ce6a69d5d77 100644 --- a/sys/netinet/ip_auth.c +++ b/sys/netinet/ip_auth.c @@ -250,7 +250,7 @@ ip_t *ip; bo = ip->ip_len; ip->ip_len = htons(bo); -# if !SOLARIS && !defined(__NetBSD__) +# if !SOLARIS && !defined(__NetBSD__) && !defined(__FreeBSD__) /* 4.4BSD converts this ip_input.c, but I don't in solaris.c */ bo = ip->ip_id; ip->ip_id = htons(bo); diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 12acdfd7761e..b2f92b823cdf 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -293,7 +293,6 @@ div_output(so, m, addr, control) /* Convert fields to host order for ip_output() */ NTOHS(ip->ip_len); - NTOHS(ip->ip_id); NTOHS(ip->ip_off); /* Send packet to output processing */ diff --git a/sys/netinet/ip_fil.c b/sys/netinet/ip_fil.c index bd76b39be349..d609f25f1f4a 100644 --- a/sys/netinet/ip_fil.c +++ b/sys/netinet/ip_fil.c @@ -1369,7 +1369,9 @@ frdest_t *fdp; i = 1; # endif # ifndef sparc +# ifndef __FreeBSD__ ip->ip_id = htons(ip->ip_id); +# endif ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); # endif diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 91c0bc085db0..dc2040ea6ba1 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -196,7 +196,6 @@ icmp_error(n, type, code, dest, destifp) * Convert fields to network representation. */ HTONS(nip->ip_len); - HTONS(nip->ip_id); HTONS(nip->ip_off); /* diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 5ba57505199c..bd04b01b4709 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -346,7 +346,6 @@ ip_input(struct mbuf *m) ipstat.ips_badlen++; goto bad; } - NTOHS(ip->ip_id); NTOHS(ip->ip_off); /* @@ -692,10 +691,8 @@ found: ip->ip_len += hlen; HTONS(ip->ip_len); HTONS(ip->ip_off); - HTONS(ip->ip_id); ip->ip_sum = 0; ip->ip_sum = in_cksum_hdr(ip); - NTOHS(ip->ip_id); NTOHS(ip->ip_off); NTOHS(ip->ip_len); ip->ip_len -= hlen; @@ -725,7 +722,6 @@ found: ip->ip_len += hlen; HTONS(ip->ip_len); HTONS(ip->ip_off); - HTONS(ip->ip_id); /* Deliver packet to divert input routine */ ip_divert_cookie = divert_cookie; diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index 73ab0393a440..1d165f5e7983 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -1581,7 +1581,7 @@ encap_send(ip, vifp, m) */ ip_copy = mtod(mb_copy, struct ip *); *ip_copy = multicast_encap_iphdr; - ip_copy->ip_id = ip_id++; + ip_copy->ip_id = htons(ip_id++); ip_copy->ip_len += len; ip_copy->ip_src = vifp->v_lcl_addr; ip_copy->ip_dst = vifp->v_rmt_addr; @@ -1592,7 +1592,6 @@ encap_send(ip, vifp, m) ip = (struct ip *)((caddr_t)ip_copy + sizeof(multicast_encap_iphdr)); --ip->ip_ttl; HTONS(ip->ip_len); - HTONS(ip->ip_id); HTONS(ip->ip_off); ip->ip_sum = 0; mb_copy->m_data += sizeof(multicast_encap_iphdr); diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 9fe700106add..baaf33239f61 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -211,7 +211,7 @@ ip_output(m0, opt, ro, flags, imo) if ((flags & (IP_FORWARDING|IP_RAWOUTPUT)) == 0) { ip->ip_vhl = IP_MAKE_VHL(IPVERSION, hlen >> 2); ip->ip_off &= IP_DF; - ip->ip_id = ip_id++; + ip->ip_id = htons(ip_id++); ipstat.ips_localout++; } else { hlen = IP_VHL_HL(ip->ip_vhl) << 2; @@ -520,7 +520,6 @@ sendit: /* Restore packet header fields to original values */ HTONS(ip->ip_len); - HTONS(ip->ip_id); HTONS(ip->ip_off); /* Deliver packet to divert input routine */ @@ -595,7 +594,6 @@ sendit: m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED | CSUM_IP_VALID; HTONS(ip->ip_len); - HTONS(ip->ip_id); HTONS(ip->ip_off); ip_input(m); goto done; @@ -715,7 +713,6 @@ pass: } HTONS(ip->ip_len); - HTONS(ip->ip_id); HTONS(ip->ip_off); error = ipsec4_output(&state, sp, flags); @@ -776,7 +773,6 @@ pass: /* make it flipped, again. */ NTOHS(ip->ip_len); - NTOHS(ip->ip_id); NTOHS(ip->ip_off); skip_ipsec: #endif /*IPSEC*/ @@ -796,7 +792,6 @@ skip_ipsec: if ((u_short)ip->ip_len <= ifp->if_mtu || ifp->if_hwassist & CSUM_FRAGMENT) { HTONS(ip->ip_len); - HTONS(ip->ip_id); HTONS(ip->ip_off); ip->ip_sum = 0; if (sw_csum & CSUM_DELAY_IP) { @@ -892,7 +887,6 @@ skip_ipsec: m->m_pkthdr.len = mhlen + len; m->m_pkthdr.rcvif = (struct ifnet *)0; m->m_pkthdr.csum_flags = m0->m_pkthdr.csum_flags; - HTONS(mhip->ip_id); HTONS(mhip->ip_off); mhip->ip_sum = 0; if (sw_csum & CSUM_DELAY_IP) { @@ -921,7 +915,6 @@ skip_ipsec: m_adj(m, hlen + firstlen - (u_short)ip->ip_len); m->m_pkthdr.len = hlen + firstlen; ip->ip_len = htons((u_short)m->m_pkthdr.len); - HTONS(ip->ip_id); ip->ip_off |= IP_MF; HTONS(ip->ip_off); ip->ip_sum = 0; @@ -1864,7 +1857,6 @@ ip_mloopback(ifp, m, dst, hlen) */ ip = mtod(copym, struct ip *); HTONS(ip->ip_len); - HTONS(ip->ip_id); HTONS(ip->ip_off); ip->ip_sum = 0; if (ip->ip_vhl == IP_VHL_BORING) { diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 94046e8a65b3..5d056cefadf6 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -221,7 +221,7 @@ rip_output(m, so, dst) return EINVAL; } if (ip->ip_id == 0) - ip->ip_id = ip_id++; + ip->ip_id = htons(ip_id++); /* XXX prevent ip_output from overwriting header fields */ flags |= IP_RAWOUTPUT; ipstat.ips_rawout++; diff --git a/sys/netinet6/ah_input.c b/sys/netinet6/ah_input.c index c50f72bdd26e..1aaa0c40c800 100644 --- a/sys/netinet6/ah_input.c +++ b/sys/netinet6/ah_input.c @@ -291,7 +291,6 @@ ah4_input(m, va_alist) * convert them back to network endian. VERY stupid. */ ip->ip_len = htons(ip->ip_len + hlen); - ip->ip_id = htons(ip->ip_id); ip->ip_off = htons(ip->ip_off); #endif if (ah4_calccksum(m, (caddr_t)cksum, siz1, algo, sav)) { @@ -305,7 +304,6 @@ ah4_input(m, va_alist) * flip them back. */ ip->ip_len = ntohs(ip->ip_len) - hlen; - ip->ip_id = ntohs(ip->ip_id); ip->ip_off = ntohs(ip->ip_off); #endif }