This is an automated email from the ASF dual-hosted git repository.

hartmannathan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new c7c5c75451 net_if: add IFF_LOOPBACK/POINTOPOINT/MULTICAST/BROADCAST
c7c5c75451 is described below

commit c7c5c754511c2ce50ab3cd83e104c0ec94477896
Author: zhanghongyu <zhanghon...@xiaomi.com>
AuthorDate: Wed Jun 1 12:47:30 2022 +0800

    net_if: add IFF_LOOPBACK/POINTOPOINT/MULTICAST/BROADCAST
    
    Signed-off-by: zhanghongyu <zhanghon...@xiaomi.com>
---
 include/net/if.h             | 66 +++++++++++++++++++++++++++-----------------
 include/nuttx/net/netdev.h   |  2 +-
 net/netdev/netdev_register.c | 12 ++++++++
 3 files changed, 54 insertions(+), 26 deletions(-)

diff --git a/include/net/if.h b/include/net/if.h
index 0dde170c00..15751e744d 100644
--- a/include/net/if.h
+++ b/include/net/if.h
@@ -46,32 +46,48 @@
 
 /* Interface flag bits */
 
-#define IFF_DOWN           (1 << 0) /* Interface is down */
-#define IFF_UP             (1 << 1) /* Interface is up */
-#define IFF_RUNNING        (1 << 2) /* Carrier is available */
-#define IFF_IPv6           (1 << 3) /* Configured for IPv6 packet (vs ARP or 
IPv4) */
-#define IFF_BOUND          (1 << 4) /* Bound to a socket */
-#define IFF_NOARP          (1 << 7) /* ARP is not required for this packet */
+#define IFF_DOWN           (1 << 0)  /* Interface is down */
+#define IFF_UP             (1 << 1)  /* Interface is up */
+#define IFF_RUNNING        (1 << 2)  /* Carrier is available */
+#define IFF_IPv6           (1 << 3)  /* Configured for IPv6 packet (vs ARP or 
IPv4) */
+#define IFF_BOUND          (1 << 4)  /* Bound to a socket */
+#define IFF_LOOPBACK       (1 << 5)  /* Is a loopback net */
+#define IFF_POINTOPOINT    (1 << 6)  /* Is point-to-point link */
+#define IFF_NOARP          (1 << 7)  /* ARP is not required for this packet */
+#define IFF_MULTICAST      (1 << 12) /* Supports multicast. */
+#define IFF_BROADCAST      (1 << 13) /* Broadcast address valid. */
 
 /* Interface flag helpers */
 
-#define IFF_SET_DOWN(f)    do { (f) |= IFF_DOWN; } while (0)
-#define IFF_SET_UP(f)      do { (f) |= IFF_UP; } while (0)
-#define IFF_SET_RUNNING(f) do { (f) |= IFF_RUNNING; } while (0)
-#define IFF_SET_BOUND(f)   do { (f) |= IFF_BOUND; } while (0)
-#define IFF_SET_NOARP(f)   do { (f) |= IFF_NOARP; } while (0)
-
-#define IFF_CLR_DOWN(f)    do { (f) &= ~IFF_DOWN; } while (0)
-#define IFF_CLR_UP(f)      do { (f) &= ~IFF_UP; } while (0)
-#define IFF_CLR_RUNNING(f) do { (f) &= ~IFF_RUNNING; } while (0)
-#define IFF_CLR_BOUND(f)   do { (f) &= ~IFF_BOUND; } while (0)
-#define IFF_CLR_NOARP(f)   do { (f) &= ~IFF_NOARP; } while (0)
-
-#define IFF_IS_DOWN(f)     (((f) & IFF_DOWN) != 0)
-#define IFF_IS_UP(f)       (((f) & IFF_UP) != 0)
-#define IFF_IS_RUNNING(f)  (((f) & IFF_RUNNING) != 0)
-#define IFF_IS_BOUND(f)    (((f) & IFF_BOUND) != 0)
-#define IFF_IS_NOARP(f)    (((f) & IFF_NOARP) != 0)
+#define IFF_SET_DOWN(f)        do { (f) |= IFF_DOWN; } while (0)
+#define IFF_SET_UP(f)          do { (f) |= IFF_UP; } while (0)
+#define IFF_SET_RUNNING(f)     do { (f) |= IFF_RUNNING; } while (0)
+#define IFF_SET_BOUND(f)       do { (f) |= IFF_BOUND; } while (0)
+#define IFF_SET_NOARP(f)       do { (f) |= IFF_NOARP; } while (0)
+#define IFF_SET_LOOPBACK(f)    do { (f) |= IFF_LOOPBACK; } while (0)
+#define IFF_SET_POINTOPOINT(f) do { (f) |= IFF_POINTOPOINT; } while (0)
+#define IFF_SET_MULTICAST(f)   do { (f) |= IFF_MULTICAST; } while (0)
+#define IFF_SET_BROADCAST(f)   do { (f) |= IFF_BROADCAST; } while (0)
+
+#define IFF_CLR_DOWN(f)        do { (f) &= ~IFF_DOWN; } while (0)
+#define IFF_CLR_UP(f)          do { (f) &= ~IFF_UP; } while (0)
+#define IFF_CLR_RUNNING(f)     do { (f) &= ~IFF_RUNNING; } while (0)
+#define IFF_CLR_BOUND(f)       do { (f) &= ~IFF_BOUND; } while (0)
+#define IFF_CLR_NOARP(f)       do { (f) &= ~IFF_NOARP; } while (0)
+#define IFF_CLR_LOOPBACK(f)    do { (f) &= ~IFF_LOOPBACK; } while (0)
+#define IFF_CLR_POINTOPOINT(f) do { (f) &= ~IFF_POINTOPOINT; } while (0)
+#define IFF_CLR_MULTICAST(f)   do { (f) &= ~IFF_MULTICAST; } while (0)
+#define IFF_CLR_BROADCAST(f)   do { (f) &= ~IFF_BROADCAST; } while (0)
+
+#define IFF_IS_DOWN(f)        (((f) & IFF_DOWN) != 0)
+#define IFF_IS_UP(f)          (((f) & IFF_UP) != 0)
+#define IFF_IS_RUNNING(f)     (((f) & IFF_RUNNING) != 0)
+#define IFF_IS_BOUND(f)       (((f) & IFF_BOUND) != 0)
+#define IFF_IS_NOARP(f)       (((f) & IFF_NOARP) != 0)
+#define IFF_IS_LOOPBACK(f)    (((f) & IFF_LOOPBACK) != 0)
+#define IFF_IS_POINTOPOINT(f) (((f) & IFF_POINTOPOINT) != 0)
+#define IFF_IS_MULTICAST(f)   (((f) & IFF_MULTICAST) != 0)
+#define IFF_IS_BROADCAST(f)   (((f) & IFF_BROADCAST) != 0)
 
 /* We only need to manage the IPv6 bit if both IPv6 and IPv4 are supported.
  * Otherwise, we can save a few bytes by ignoring it.
@@ -184,7 +200,7 @@ struct lifreq
     struct sockaddr            lifru_hwaddr;         /* MAC address */
     int                        lifru_count;          /* Number of devices */
     int                        lifru_mtu;            /* MTU size */
-    uint8_t                    lifru_flags;          /* Interface flags */
+    uint32_t                   lifru_flags;          /* Interface flags */
     struct mii_ioctl_notify_s  llfru_mii_notify;     /* PHY event notification 
*/
     struct mii_ioctl_data_s    lifru_mii_data;       /* MII request data */
     struct can_ioctl_data_s    lifru_can_data;       /* CAN bitrate request 
data */
@@ -237,7 +253,7 @@ struct ifreq
     struct sockaddr            ifru_hwaddr;         /* MAC address */
     int                        ifru_count;          /* Number of devices */
     int                        ifru_mtu;            /* MTU size */
-    uint8_t                    ifru_flags;          /* Interface flags */
+    uint32_t                   ifru_flags;          /* Interface flags */
     struct mii_ioctl_notify_s  ifru_mii_notify;     /* PHY event notification 
*/
     struct mii_ioctl_data_s    ifru_mii_data;       /* MII request data */
     struct can_ioctl_data_s    ifru_can_data;       /* CAN bitrate request 
data */
diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h
index fe55aab079..862e862c67 100644
--- a/include/nuttx/net/netdev.h
+++ b/include/nuttx/net/netdev.h
@@ -242,7 +242,7 @@ struct net_driver_s
 
   /* Drivers interface flags.  See IFF_* definitions in include/net/if.h */
 
-  uint8_t d_flags;
+  uint32_t d_flags;
 
   /* Multi network devices using multiple link layer protocols are
    * supported
diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c
index c44510ee82..be95534895 100644
--- a/net/netdev/netdev_register.c
+++ b/net/netdev/netdev_register.c
@@ -243,6 +243,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
   FAR struct net_driver_s **last;
   FAR char devfmt_str[IFNAMSIZ];
   FAR const char *devfmt;
+  uint32_t flags   = 0;
   uint16_t pktsize = 0;
   uint8_t llhdrlen = 0;
   int devnum;
@@ -263,6 +264,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
             llhdrlen = 0;
             pktsize  = NET_LO_PKTSIZE;
             devfmt   = NETDEV_LO_FORMAT;
+            flags    = IFF_LOOPBACK;
             break;
 #endif
 
@@ -271,6 +273,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
             llhdrlen = ETH_HDRLEN;
             pktsize  = CONFIG_NET_ETH_PKTSIZE;
             devfmt   = NETDEV_ETH_FORMAT;
+            flags    = IFF_BROADCAST | IFF_MULTICAST;
             break;
 #endif
 
@@ -279,6 +282,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
             llhdrlen = ETH_HDRLEN;
             pktsize  = CONFIG_NET_ETH_PKTSIZE;
             devfmt   = NETDEV_WLAN_FORMAT;
+            flags    = IFF_BROADCAST | IFF_MULTICAST;
             break;
 #endif
 
@@ -287,6 +291,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
             dev->d_llhdrlen = 0;
             dev->d_pktsize  = NET_CAN_PKTSIZE;
             devfmt          = NETDEV_CAN_FORMAT;
+            flags           = IFF_NOARP;
             break;
 #endif
 
@@ -297,6 +302,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
             pktsize  = CONFIG_NET_6LOWPAN_PKTSIZE;
 #endif
             devfmt   = NETDEV_BNEP_FORMAT;
+            flags    = IFF_BROADCAST | IFF_MULTICAST;
             break;
 #endif
 
@@ -308,6 +314,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
             pktsize  = CONFIG_NET_6LOWPAN_PKTSIZE;
 #endif
             devfmt   = NETDEV_WPAN_FORMAT;
+            flags    = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
             break;
 #endif
 
@@ -316,6 +323,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
             llhdrlen = 0;
             pktsize  = CONFIG_NET_SLIP_PKTSIZE;
             devfmt   = NETDEV_SLIP_FORMAT;
+            flags    = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
             break;
 #endif
 
@@ -325,6 +333,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
                                    * if used as a TAP (layer 2) device */
             pktsize  = CONFIG_NET_TUN_PKTSIZE;
             devfmt   = NETDEV_TUN_FORMAT;
+            flags    = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
             break;
 #endif
 
@@ -333,6 +342,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
             llhdrlen = 0;
             pktsize  = 1200;
             devfmt   = NETDEV_WWAN_FORMAT;
+            flags    = IFF_BROADCAST | IFF_NOARP | IFF_MULTICAST;
             break;
 #endif
 
@@ -357,6 +367,8 @@ int netdev_register(FAR struct net_driver_s *dev, enum 
net_lltype_e lltype)
           dev->d_pktsize = pktsize;
         }
 
+      dev->d_flags |= flags;
+
       /* Remember the verified link type */
 
       dev->d_lltype = (uint8_t)lltype;

Reply via email to