Here's an updated version of a diff I sent some months ago.

It removes the dependency on <netinet/in_systm.h> for the network
headers by substituting n_time, n_long and n_short by their equivalent
u_int_* types.

This will allows to stop including <netinet/in_systm.h> in all the
files pulling <netinet/ip.h> or <netinet/ip_icmp.h>.  Here's what I
said in my previous mail:

> Since in most of the protocol header definitions we generally use
> u_intX_t types and then call the appropriate ntohX() function on
> every field, can't we do the same here?
> 
> The diff below converts all of the n_* declaration under sys/netinet
> and leave sys/lib/libsa for the moment.
> 
> Apart from reducing the obfuscating factor of our sources this change
> would allow us to remove an include from ~400 files.

Only one program in userland uses n_time, trpt(8), it can be cleaned
when removing the <netinet/in_systm.h> include.

ok?


Index: netinet/in_systm.h
===================================================================
RCS file: /cvs/src/sys/netinet/in_systm.h,v
retrieving revision 1.6
diff -u -p -r1.6 in_systm.h
--- netinet/in_systm.h  19 Oct 2013 14:50:21 -0000      1.6
+++ netinet/in_systm.h  13 Jul 2014 07:48:23 -0000
@@ -41,7 +41,7 @@ typedef u_int32_t n_long;
 typedef u_int32_t n_time;              /* ms since 00:00 GMT */
 
 #ifdef _KERNEL
-n_time  iptime(void);
+u_int32_t iptime(void);
 #endif /* _KERNEL */
 
 #endif /* _NETINET_IN_SYSTM_H_ */
Index: netinet/ip.h
===================================================================
RCS file: /cvs/src/sys/netinet/ip.h,v
retrieving revision 1.15
diff -u -p -r1.15 ip.h
--- netinet/ip.h        12 May 2014 09:15:00 -0000      1.15
+++ netinet/ip.h        13 Jul 2014 07:48:23 -0000
@@ -176,10 +176,10 @@ struct    ip_timestamp {
                 ipt_flg:4;             /* flags, see below */
 #endif
        union ipt_timestamp {
-                n_time ipt_time[1];
+                u_int32_t ipt_time[1];
                 struct ipt_ta {
                        struct in_addr ipt_addr;
-                       n_time ipt_time;
+                       u_int32_t ipt_time;
                 } ipt_ta[1];
        } ipt_timestamp;
 };
Index: netinet/ip_icmp.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_icmp.c,v
retrieving revision 1.122
diff -u -p -r1.122 ip_icmp.c
--- netinet/ip_icmp.c   7 May 2014 08:09:33 -0000       1.122
+++ netinet/ip_icmp.c   13 Jul 2014 07:48:23 -0000
@@ -143,7 +143,7 @@ icmp_init(void)
 }
 
 struct mbuf *
-icmp_do_error(struct mbuf *n, int type, int code, n_long dest, int destmtu)
+icmp_do_error(struct mbuf *n, int type, int code, u_int32_t dest, int destmtu)
 {
        struct ip *oip = mtod(n, struct ip *), *nip;
        unsigned oiplen = oip->ip_hl << 2;
@@ -289,7 +289,7 @@ freeit:
  * The ip packet inside has ip_off and ip_len in host byte order.
  */
 void
-icmp_error(struct mbuf *n, int type, int code, n_long dest, int destmtu)
+icmp_error(struct mbuf *n, int type, int code, u_int32_t dest, int destmtu)
 {
        struct mbuf *m;
 
@@ -849,7 +849,7 @@ icmp_send(struct mbuf *m, struct mbuf *o
        ip_output(m, opts, NULL, 0, NULL, NULL, 0);
 }
 
-n_time
+u_int32_t
 iptime(void)
 {
        struct timeval atv;
Index: netinet/ip_icmp.h
===================================================================
RCS file: /cvs/src/sys/netinet/ip_icmp.h,v
retrieving revision 1.25
diff -u -p -r1.25 ip_icmp.h
--- netinet/ip_icmp.h   8 Aug 2013 14:29:29 -0000       1.25
+++ netinet/ip_icmp.h   13 Jul 2014 07:48:23 -0000
@@ -51,8 +51,8 @@
  * ICMP Router Advertisement data
  */
 struct icmp_ra_addr {
-       n_long ira_addr;
-       n_long ira_preference;
+       u_int32_t ira_addr;
+       u_int32_t ira_preference;
 };
 
 /*
@@ -70,21 +70,21 @@ struct icmp {
                } ih_exthdr;
                struct in_addr ih_gwaddr;       /* ICMP_REDIRECT */
                struct ih_idseq {
-                         n_short icd_id;
-                         n_short icd_seq;
+                         u_int16_t icd_id;
+                         u_int16_t icd_seq;
                } ih_idseq;
                int32_t   ih_void;
 
                /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
                struct ih_pmtu {
-                         n_short ipm_void;
-                         n_short ipm_nextmtu;
+                         u_int16_t ipm_void;
+                         u_int16_t ipm_nextmtu;
                } ih_pmtu;
 
                struct ih_rtradv {
                        u_int8_t irt_num_addrs;
                        u_int8_t irt_wpa;
-                       n_short irt_lifetime;
+                       u_int16_t irt_lifetime;
                } ih_rtradv;
        } icmp_hun;
 #define        icmp_pptr         icmp_hun.ih_pptr
@@ -100,9 +100,9 @@ struct icmp {
 #define        icmp_lifetime     icmp_hun.ih_rtradv.irt_lifetime
        union {
                struct id_ts {
-                         n_time its_otime;
-                         n_time its_rtime;
-                         n_time its_ttime;
+                         u_int32_t its_otime;
+                         u_int32_t its_rtime;
+                         u_int32_t its_ttime;
                } id_ts;
                struct id_ip  {
                          struct ip idi_ip;
@@ -153,7 +153,7 @@ struct icmp_ext_obj_hdr {
  * ip header length.
  */
 #define        ICMP_MINLEN     8                               /* abs minimum 
*/
-#define        ICMP_TSLEN      (8 + 3 * sizeof (n_time))       /* timestamp */
+#define        ICMP_TSLEN      (8 + 3 * sizeof (u_int32_t))    /* timestamp */
 #define        ICMP_MASKLEN    12                              /* address mask 
*/
 #define        ICMP_ADVLENMIN  (8 + sizeof (struct ip) + 8)    /* min */
 #define        ICMP_ADVLEN(p)  (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
@@ -230,8 +230,8 @@ struct icmp_ext_obj_hdr {
 
 #ifdef _KERNEL
 struct mbuf *
-       icmp_do_error(struct mbuf *, int, int, n_long, int);
-void   icmp_error(struct mbuf *, int, int, n_long, int);
+       icmp_do_error(struct mbuf *, int, int, u_int32_t, int);
+void   icmp_error(struct mbuf *, int, int, u_int32_t, int);
 void   icmp_input(struct mbuf *, ...);
 void   icmp_init(void);
 int    icmp_reflect(struct mbuf *, struct mbuf **, struct in_ifaddr *);
Index: netinet/ip_input.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.234
diff -u -p -r1.234 ip_input.c
--- netinet/ip_input.c  4 Jun 2014 12:20:00 -0000       1.234
+++ netinet/ip_input.c  13 Jul 2014 07:48:23 -0000
@@ -1008,7 +1008,7 @@ ip_dooptions(struct mbuf *m, struct ifne
        struct in_ifaddr *ia;
        int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0;
        struct in_addr sin, dst;
-       n_time ntime;
+       u_int32_t ntime;
 
        dst = ip->ip_dst;
        cp = (u_char *)(ip + 1);
@@ -1161,7 +1161,7 @@ ip_dooptions(struct mbuf *m, struct ifne
                        memcpy(&ipt, cp, sizeof(struct ip_timestamp));
                        if (ipt.ipt_ptr < 5 || ipt.ipt_len < 5)
                                goto bad;
-                       if (ipt.ipt_ptr - 1 + sizeof(n_time) > ipt.ipt_len) {
+                       if (ipt.ipt_ptr - 1 + sizeof(u_int32_t) > ipt.ipt_len) {
                                if (++ipt.ipt_oflw == 0)
                                        goto bad;
                                break;
@@ -1173,7 +1173,7 @@ ip_dooptions(struct mbuf *m, struct ifne
                                break;
 
                        case IPOPT_TS_TSANDADDR:
-                               if (ipt.ipt_ptr - 1 + sizeof(n_time) +
+                               if (ipt.ipt_ptr - 1 + sizeof(u_int32_t) +
                                    sizeof(struct in_addr) > ipt.ipt_len)
                                        goto bad;
                                memset(&ipaddr, 0, sizeof(ipaddr));
@@ -1190,7 +1190,7 @@ ip_dooptions(struct mbuf *m, struct ifne
                                break;
 
                        case IPOPT_TS_PRESPEC:
-                               if (ipt.ipt_ptr - 1 + sizeof(n_time) +
+                               if (ipt.ipt_ptr - 1 + sizeof(u_int32_t) +
                                    sizeof(struct in_addr) > ipt.ipt_len)
                                        goto bad;
                                memset(&ipaddr, 0, sizeof(ipaddr));
@@ -1210,8 +1210,8 @@ ip_dooptions(struct mbuf *m, struct ifne
                                goto bad;
                        }
                        ntime = iptime();
-                       memcpy(cp + ipt.ipt_ptr - 1, &ntime, sizeof(n_time));
-                       ipt.ipt_ptr += sizeof(n_time);
+                       memcpy(cp + ipt.ipt_ptr - 1, &ntime, sizeof(u_int32_t));
+                       ipt.ipt_ptr += sizeof(u_int32_t);
                }
        }
        if (forward && ipforwarding) {
@@ -1396,7 +1396,7 @@ ip_forward(struct mbuf *m, struct ifnet 
        struct rtentry *rt;
        int error, type = 0, code = 0, destmtu = 0, fake = 0, len;
        u_int rtableid = 0;
-       n_long dest;
+       u_int32_t dest;
 
        dest = 0;
        if (m->m_flags & (M_BCAST|M_MCAST) || in_canforward(ip->ip_dst) == 0) {
Index: netinet/tcp_debug.h
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_debug.h,v
retrieving revision 1.7
diff -u -p -r1.7 tcp_debug.h
--- netinet/tcp_debug.h 2 Jun 2003 23:28:14 -0000       1.7
+++ netinet/tcp_debug.h 13 Jul 2014 07:48:23 -0000
@@ -38,7 +38,7 @@
 #include <netinet6/tcpipv6.h>
 
 struct tcp_debug {
-       n_time  td_time;
+       uint32_t td_time;
        short   td_act;
        short   td_ostate;
        caddr_t td_tcb;

Reply via email to