Skip to content

Commit

Permalink
tipc: relocate common functions from media to bearer
Browse files Browse the repository at this point in the history
Currently, registering a TIPC stack handler in the network device layer
is done twice, once for Ethernet (eth_media) and Infiniband (ib_media)
repectively. But, as this registration is not media specific, we can
avoid some code duplication by moving the registering function to
the generic bearer layer, to the file bearer.c, and call it only once.
The same is true for the network device event notifier.

As a side effect, the two workqueues we are using for for setting up/
cleaning up media can now be eliminated. Furthermore, the array for
storing the specific media type structs, media_array[], can be entirely
deleted.

Note that the eth_started and ib_started flags were removed during the
code relocation.  There is now only one call to bearer_setup and
bearer_cleanup, and these can logically not race against each other.

Despite its size, this cleanup work incurs no functional changes in TIPC.
In particular, it should be noted that the sequence ordering of received
packets is unaffected by this change, since packet reception never was
subject to any work queue handling in the first place.

Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Patrick McHardy <kaber@trash.net>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ying Xue authored and David S. Miller committed Dec 11, 2013
1 parent 37cb062 commit 6e967ad
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 401 deletions.
105 changes: 104 additions & 1 deletion net/tipc/bearer.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
/**
* tipc_reset_bearer - Reset all links established over this bearer
*/
int tipc_reset_bearer(struct tipc_bearer *b_ptr)
static int tipc_reset_bearer(struct tipc_bearer *b_ptr)
{
struct tipc_link *l_ptr;
struct tipc_link *temp_l_ptr;
Expand Down Expand Up @@ -432,7 +432,110 @@ int tipc_disable_bearer(const char *name)
return res;
}

/**
* tipc_l2_rcv_msg - handle incoming TIPC message from an interface
* @buf: the received packet
* @dev: the net device that the packet was received on
* @pt: the packet_type structure which was used to register this handler
* @orig_dev: the original receive net device in case the device is a bond
*
* Accept only packets explicitly sent to this node, or broadcast packets;
* ignores packets sent using interface multicast, and traffic sent to other
* nodes (which can happen if interface is running in promiscuous mode).
*/
static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev)
{
struct tipc_bearer *b_ptr;

if (!net_eq(dev_net(dev), &init_net)) {
kfree_skb(buf);
return NET_RX_DROP;
}

rcu_read_lock();
b_ptr = rcu_dereference(dev->tipc_ptr);
if (likely(b_ptr)) {
if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
buf->next = NULL;
tipc_recv_msg(buf, b_ptr);
rcu_read_unlock();
return NET_RX_SUCCESS;
}
}
rcu_read_unlock();

kfree_skb(buf);
return NET_RX_DROP;
}

/**
* tipc_l2_device_event - handle device events from network device
* @nb: the context of the notification
* @evt: the type of event
* @ptr: the net device that the event was on
*
* This function is called by the Ethernet driver in case of link
* change event.
*/
static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
void *ptr)
{
struct tipc_bearer *b_ptr;
struct net_device *dev = netdev_notifier_info_to_dev(ptr);

if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

rcu_read_lock();
b_ptr = rcu_dereference(dev->tipc_ptr);
if (!b_ptr) {
rcu_read_unlock();
return NOTIFY_DONE;
}

b_ptr->mtu = dev->mtu;

switch (evt) {
case NETDEV_CHANGE:
if (netif_carrier_ok(dev))
break;
case NETDEV_DOWN:
case NETDEV_CHANGEMTU:
case NETDEV_CHANGEADDR:
tipc_reset_bearer(b_ptr);
break;
case NETDEV_UNREGISTER:
case NETDEV_CHANGENAME:
tipc_disable_bearer(b_ptr->name);
break;
}
rcu_read_unlock();

return NOTIFY_OK;
}

static struct packet_type tipc_packet_type __read_mostly = {
.type = __constant_htons(ETH_P_TIPC),
.func = tipc_l2_rcv_msg,
};

static struct notifier_block notifier = {
.notifier_call = tipc_l2_device_event,
.priority = 0,
};

int tipc_bearer_setup(void)
{
dev_add_pack(&tipc_packet_type);
return register_netdevice_notifier(&notifier);
}

void tipc_bearer_cleanup(void)
{
unregister_netdevice_notifier(&notifier);
dev_remove_pack(&tipc_packet_type);
}

void tipc_bearer_stop(void)
{
Expand Down
11 changes: 2 additions & 9 deletions net/tipc/bearer.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,16 @@ extern struct tipc_bearer tipc_bearers[];

void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr);

int tipc_reset_bearer(struct tipc_bearer *b_ptr);

int tipc_enable_bearer(const char *bearer_name, u32 disc_domain, u32 priority);
int tipc_disable_bearer(const char *name);

/*
* Routines made available to TIPC by supported media types
*/
int tipc_eth_media_start(void);
void tipc_eth_media_stop(void);
extern struct tipc_media eth_media_info;

#ifdef CONFIG_TIPC_MEDIA_IB
int tipc_ib_media_start(void);
void tipc_ib_media_stop(void);
extern struct tipc_media ib_media_info;
#else
static inline int tipc_ib_media_start(void) { return 0; }
static inline void tipc_ib_media_stop(void) { return; }
#endif

int tipc_media_set_priority(const char *name, u32 new_value);
Expand All @@ -194,6 +185,8 @@ void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest);
struct tipc_bearer *tipc_bearer_find(const char *name);
struct tipc_bearer *tipc_bearer_find_interface(const char *if_name);
struct tipc_media *tipc_media_find(const char *name);
int tipc_bearer_setup(void);
void tipc_bearer_cleanup(void);
void tipc_bearer_stop(void);

/**
Expand Down
8 changes: 2 additions & 6 deletions net/tipc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ struct sk_buff *tipc_buf_acquire(u32 size)
static void tipc_core_stop_net(void)
{
tipc_net_stop();
tipc_eth_media_stop();
tipc_ib_media_stop();
tipc_bearer_cleanup();
}

/**
Expand All @@ -94,10 +93,7 @@ int tipc_core_start_net(unsigned long addr)
int res;

tipc_net_start(addr);
res = tipc_eth_media_start();
if (res < 0)
goto err;
res = tipc_ib_media_start();
res = tipc_bearer_setup();
if (res < 0)
goto err;
return res;
Expand Down
Loading

0 comments on commit 6e967ad

Please sign in to comment.