Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Define ar_* as inlined functions, not as macros. Mak...



details:   https://anonhg.NetBSD.org/src/rev/13bda83db105
branches:  trunk
changeset: 359503:13bda83db105
user:      maxv <maxv%NetBSD.org@localhost>
date:      Tue Feb 13 08:43:26 2018 +0000

description:
Define ar_* as inlined functions, not as macros. Makes it easier to
understand why ARPHRD_IEEE1394 needs to be handled with care - it doesn't
have ar_tha.

diffstat:

 sys/net/if_arp.h |  45 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 34 insertions(+), 11 deletions(-)

diffs (63 lines):

diff -r b027637cdad3 -r 13bda83db105 sys/net/if_arp.h
--- a/sys/net/if_arp.h  Tue Feb 13 08:20:12 2018 +0000
+++ b/sys/net/if_arp.h  Tue Feb 13 08:43:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.h,v 1.30 2015/08/31 08:05:20 ozaki-r Exp $      */
+/*     $NetBSD: if_arp.h,v 1.31 2018/02/13 08:43:26 maxv Exp $ */
 
 /*
  * Copyright (c) 1986, 1993
@@ -68,20 +68,43 @@
 #ifdef COMMENT_ONLY
        uint8_t  ar_sha[];      /* sender hardware address */
        uint8_t  ar_spa[];      /* sender protocol address */
-       uint8_t  ar_tha[];      /* target hardware address */
+       uint8_t  ar_tha[];      /* target hardware address (!IEEE1394) */
        uint8_t  ar_tpa[];      /* target protocol address */
 #endif
-#define ar_sha(ap) (((char *)((ap)+1))+0)
-#define ar_spa(ap) (((char *)((ap)+1))+(ap)->ar_hln)
-#define ar_tha(ap) \
-       (ntohs((ap)->ar_hrd) == ARPHRD_IEEE1394 \
-               ? NULL : (((char *)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln))
-#define ar_tpa(ap) \
-       (ntohs((ap)->ar_hrd) == ARPHRD_IEEE1394 \
-               ? (((char *)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln) \
-               : (((char *)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln+(ap)->ar_hln))
 } __packed;
 
+static inline uint8_t *
+ar_sha(struct arphdr *ap)
+{
+       return ((uint8_t *)(ap + 1)) + 0;
+}
+
+static inline uint8_t *
+ar_spa(struct arphdr *ap)
+{
+       return ((uint8_t *)(ap + 1)) + ap->ar_hln;
+}
+
+static inline uint8_t *
+ar_tha(struct arphdr *ap)
+{
+       if (ntohs(ap->ar_hrd) == ARPHRD_IEEE1394) {
+               return NULL;
+       } else {
+               return ((uint8_t *)(ap + 1)) + ap->ar_hln + ap->ar_pln;
+       }
+}
+
+static inline uint8_t *
+ar_tpa(struct arphdr *ap)
+{
+       if (ntohs(ap->ar_hrd) == ARPHRD_IEEE1394) {
+               return ((uint8_t *)(ap + 1)) + ap->ar_hln + ap->ar_pln;
+       } else {
+               return ((uint8_t *)(ap + 1)) + ap->ar_hln + ap->ar_pln +
+                   ap->ar_hln;
+       }
+}
 
 /*
  * ARP ioctl request



Home | Main Index | Thread Index | Old Index