Skip to content
Permalink
Browse files

net: if: Add access functions for network interface flags

Provide access functions for manipulating network interface flags.
There is no need for the caller of this API to know about the inner
details of the flags.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Apr 16, 2019
1 parent fcf392c commit 712103d594ea08a9b195b7c59ad52787a22f6b42
@@ -1310,7 +1310,7 @@ static void wncm14a2a_modem_reset(void)
int ret = 0, retry_count = 0, counter = 0;

/* bring down network interface */
atomic_clear_bit(ictx.iface->if_dev->flags, NET_IF_UP);
net_if_flag_clear(ictx.iface, NET_IF_UP);

restart:
/* stop RSSI delay work */
@@ -169,7 +169,7 @@ struct net_if_router {
*/
#define __net_if_align __aligned(32)

enum {
enum net_if_flag {
/** Interface is up/ready to receive and transmit */
NET_IF_UP,

@@ -452,6 +452,66 @@ struct net_if {
struct net_if_config config;
} __net_if_align;

/**
* @brief Set a value in network interface flags
*
* @param iface Pointer to network interface
* @param value Flag value
*/
static inline void net_if_flag_set(struct net_if *iface,
enum net_if_flag value)
{
NET_ASSERT(iface);

atomic_set_bit(iface->if_dev->flags, value);
}

/**
* @brief Test and set a value in network interface flags
*
* @param iface Pointer to network interface
* @param value Flag value
*
* @return true if the bit was set, false if it wasn't.
*/
static inline bool net_if_flag_test_and_set(struct net_if *iface,
enum net_if_flag value)
{
NET_ASSERT(iface);

return atomic_test_and_set_bit(iface->if_dev->flags, value);
}

/**
* @brief Clear a value in network interface flags
*
* @param iface Pointer to network interface
* @param value Flag value
*/
static inline void net_if_flag_clear(struct net_if *iface,
enum net_if_flag value)
{
NET_ASSERT(iface);

atomic_clear_bit(iface->if_dev->flags, value);
}

/**
* @brief Check if a value in network interface flags is set
*
* @param iface Pointer to network interface
* @param value Flag value
*
* @return True if the value is set, false otherwise
*/
static inline bool net_if_flag_is_set(struct net_if *iface,
enum net_if_flag value)
{
NET_ASSERT(iface);

return atomic_test_bit(iface->if_dev->flags, value);
}

/**
* @brief Send a packet through a net iface
*
@@ -607,7 +667,7 @@ static inline int net_if_set_link_addr(struct net_if *iface,
u8_t *addr, u8_t len,
enum net_link_type type)
{
if (atomic_test_bit(iface->if_dev->flags, NET_IF_UP)) {
if (net_if_flag_is_set(iface, NET_IF_UP)) {
return -EPERM;
}

@@ -1684,7 +1744,7 @@ static inline bool net_if_is_up(struct net_if *iface)
{
NET_ASSERT(iface);

return atomic_test_bit(iface->if_dev->flags, NET_IF_UP);
return net_if_flag_is_set(iface, NET_IF_UP);
}

/**
@@ -841,8 +841,8 @@ enum net_verdict net_ipv6_prepare_for_send(struct net_pkt *pkt)
/* Workaround Linux bug, see:
* https://github.com/zephyrproject-rtos/zephyr/issues/3111
*/
atomic_test_bit(net_pkt_iface(pkt)->if_dev->flags,
NET_IF_POINTOPOINT)) {
net_if_flag_is_set(net_pkt_iface(pkt),
NET_IF_POINTOPOINT)) {
return NET_OK;
}

@@ -388,7 +388,7 @@ int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
return -ENODATA;
}

if (!atomic_test_bit(iface->if_dev->flags, NET_IF_UP)) {
if (!net_if_flag_is_set(iface, NET_IF_UP)) {
return -ENETDOWN;
}

@@ -150,7 +150,7 @@ static bool net_if_tx(struct net_if *iface, struct net_pkt *pkt)
dst = net_pkt_lladdr_dst(pkt);
context = net_pkt_context(pkt);

if (atomic_test_bit(iface->if_dev->flags, NET_IF_UP)) {
if (net_if_flag_is_set(iface, NET_IF_UP)) {
if (IS_ENABLED(CONFIG_NET_TCP) &&
net_pkt_family(pkt) != AF_UNSPEC) {
net_pkt_set_sent(pkt, true);
@@ -231,7 +231,7 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
enum net_verdict verdict = NET_OK;
int status = -EIO;

if (!atomic_test_bit(iface->if_dev->flags, NET_IF_UP)) {
if (!net_if_flag_is_set(iface, NET_IF_UP)) {
/* Drop packet if interface is not up */
NET_WARN("iface %p is down", iface);
verdict = NET_DROP;
@@ -244,7 +244,7 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
* Workaround Linux bug, see:
* https://github.com/zephyrproject-rtos/zephyr/issues/3111
*/
if (!atomic_test_bit(iface->if_dev->flags, NET_IF_POINTOPOINT) &&
if (!net_if_flag_is_set(iface, NET_IF_POINTOPOINT) &&
!net_pkt_lladdr_src(pkt)->addr) {
net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_if(pkt)->addr;
net_pkt_lladdr_src(pkt)->len = net_pkt_lladdr_if(pkt)->len;
@@ -2839,7 +2839,7 @@ int net_if_up(struct net_if *iface)

NET_DBG("iface %p", iface);

if (atomic_test_bit(iface->if_dev->flags, NET_IF_UP)) {
if (net_if_flag_is_set(iface, NET_IF_UP)) {
return 0;
}

@@ -2866,7 +2866,7 @@ int net_if_up(struct net_if *iface)
*/
NET_ASSERT(net_if_get_link_addr(iface)->addr != NULL);

atomic_set_bit(iface->if_dev->flags, NET_IF_UP);
net_if_flag_set(iface, NET_IF_UP);

#if defined(CONFIG_NET_IPV6_DAD)
NET_DBG("Starting DAD for iface %p", iface);
@@ -2894,7 +2894,7 @@ void net_if_carrier_down(struct net_if *iface)
{
NET_DBG("iface %p", iface);

atomic_clear_bit(iface->if_dev->flags, NET_IF_UP);
net_if_flag_clear(iface, NET_IF_UP);

#if defined(CONFIG_NET_IPV4_AUTO)
net_ipv4_autoconf_reset(iface);
@@ -2929,7 +2929,7 @@ int net_if_down(struct net_if *iface)
}

done:
atomic_clear_bit(iface->if_dev->flags, NET_IF_UP);
net_if_flag_clear(iface, NET_IF_UP);

net_mgmt_event_notify(NET_EVENT_IF_DOWN, iface);

@@ -2974,7 +2974,7 @@ int net_if_set_promisc(struct net_if *iface)
return ret;
}

ret = atomic_test_and_set_bit(iface->if_dev->flags, NET_IF_PROMISC);
ret = net_if_flag_test_and_set(iface, NET_IF_PROMISC);
if (ret) {
return -EALREADY;
}
@@ -2991,14 +2991,14 @@ void net_if_unset_promisc(struct net_if *iface)
return;
}

atomic_clear_bit(iface->if_dev->flags, NET_IF_PROMISC);
net_if_flag_clear(iface, NET_IF_PROMISC);
}

bool net_if_is_promisc(struct net_if *iface)
{
NET_ASSERT(iface);

return atomic_test_bit(iface->if_dev->flags, NET_IF_PROMISC);
return net_if_flag_is_set(iface, NET_IF_PROMISC);
}

#if defined(CONFIG_NET_PKT_TIMESTAMP)
@@ -260,7 +260,7 @@ static void bt_iface_init(struct net_if *iface)
/* Workaround Linux bug, see:
* https://github.com/zephyrproject-rtos/zephyr/issues/3111
*/
atomic_set_bit(iface->if_dev->flags, NET_IF_POINTOPOINT);
net_if_flag_set(iface, NET_IF_POINTOPOINT);
#endif
}

@@ -313,7 +313,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
* immediately. If the interface is not ethernet one, then
* lldp_start() will return immediately.
*/
if (atomic_test_bit(iface->if_dev->flags, NET_IF_UP)) {
if (net_if_flag_is_set(iface, NET_IF_UP)) {
lldp_start(iface, NET_EVENT_IF_UP);
}
}

0 comments on commit 712103d

Please sign in to comment.
You can’t perform that action at this time.