Skip to content

Commit 4d8642d

Browse files
Jon Paul Maloydavem330
authored andcommitted
tipc: modify struct tipc_plist to be more versatile
During multicast reception we currently use a simple linked list with push/pop semantics to store port numbers. We now see a need for a more generic list for storing values of type u32. We therefore make some modifications to this list, while replacing the prefix 'tipc_plist_' with 'u32_'. We also add a couple of new functions which will come to use in the next commits. Acked-by: Parthasarathy Bhuvaragan <[email protected]> Acked-by: Ying Xue <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8c44e1a commit 4d8642d

File tree

3 files changed

+83
-46
lines changed

3 files changed

+83
-46
lines changed

net/tipc/name_table.c

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance,
608608
* Returns non-zero if any off-node ports overlap
609609
*/
610610
int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper,
611-
u32 limit, struct tipc_plist *dports)
611+
u32 limit, struct list_head *dports)
612612
{
613613
struct name_seq *seq;
614614
struct sub_seq *sseq;
@@ -633,7 +633,7 @@ int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper,
633633
info = sseq->info;
634634
list_for_each_entry(publ, &info->node_list, node_list) {
635635
if (publ->scope <= limit)
636-
tipc_plist_push(dports, publ->ref);
636+
u32_push(dports, publ->ref);
637637
}
638638

639639
if (info->cluster_list_size != info->node_list_size)
@@ -1022,40 +1022,84 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb)
10221022
return skb->len;
10231023
}
10241024

1025-
void tipc_plist_push(struct tipc_plist *pl, u32 port)
1025+
struct u32_item {
1026+
struct list_head list;
1027+
u32 value;
1028+
};
1029+
1030+
bool u32_find(struct list_head *l, u32 value)
10261031
{
1027-
struct tipc_plist *nl;
1032+
struct u32_item *item;
10281033

1029-
if (likely(!pl->port)) {
1030-
pl->port = port;
1031-
return;
1034+
list_for_each_entry(item, l, list) {
1035+
if (item->value == value)
1036+
return true;
10321037
}
1033-
if (pl->port == port)
1034-
return;
1035-
list_for_each_entry(nl, &pl->list, list) {
1036-
if (nl->port == port)
1037-
return;
1038+
return false;
1039+
}
1040+
1041+
bool u32_push(struct list_head *l, u32 value)
1042+
{
1043+
struct u32_item *item;
1044+
1045+
list_for_each_entry(item, l, list) {
1046+
if (item->value == value)
1047+
return false;
1048+
}
1049+
item = kmalloc(sizeof(*item), GFP_ATOMIC);
1050+
if (unlikely(!item))
1051+
return false;
1052+
1053+
item->value = value;
1054+
list_add(&item->list, l);
1055+
return true;
1056+
}
1057+
1058+
u32 u32_pop(struct list_head *l)
1059+
{
1060+
struct u32_item *item;
1061+
u32 value = 0;
1062+
1063+
if (list_empty(l))
1064+
return 0;
1065+
item = list_first_entry(l, typeof(*item), list);
1066+
value = item->value;
1067+
list_del(&item->list);
1068+
kfree(item);
1069+
return value;
1070+
}
1071+
1072+
bool u32_del(struct list_head *l, u32 value)
1073+
{
1074+
struct u32_item *item, *tmp;
1075+
1076+
list_for_each_entry_safe(item, tmp, l, list) {
1077+
if (item->value != value)
1078+
continue;
1079+
list_del(&item->list);
1080+
kfree(item);
1081+
return true;
10381082
}
1039-
nl = kmalloc(sizeof(*nl), GFP_ATOMIC);
1040-
if (nl) {
1041-
nl->port = port;
1042-
list_add(&nl->list, &pl->list);
1083+
return false;
1084+
}
1085+
1086+
void u32_list_purge(struct list_head *l)
1087+
{
1088+
struct u32_item *item, *tmp;
1089+
1090+
list_for_each_entry_safe(item, tmp, l, list) {
1091+
list_del(&item->list);
1092+
kfree(item);
10431093
}
10441094
}
10451095

1046-
u32 tipc_plist_pop(struct tipc_plist *pl)
1096+
int u32_list_len(struct list_head *l)
10471097
{
1048-
struct tipc_plist *nl;
1049-
u32 port = 0;
1098+
struct u32_item *item;
1099+
int i = 0;
10501100

1051-
if (likely(list_empty(&pl->list))) {
1052-
port = pl->port;
1053-
pl->port = 0;
1054-
return port;
1101+
list_for_each_entry(item, l, list) {
1102+
i++;
10551103
}
1056-
nl = list_first_entry(&pl->list, typeof(*nl), list);
1057-
port = nl->port;
1058-
list_del(&nl->list);
1059-
kfree(nl);
1060-
return port;
1104+
return i;
10611105
}

net/tipc/name_table.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb);
9999

100100
u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *node);
101101
int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper,
102-
u32 limit, struct tipc_plist *dports);
102+
u32 limit, struct list_head *dports);
103103
struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower,
104104
u32 upper, u32 scope, u32 port_ref,
105105
u32 key);
@@ -116,18 +116,11 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *s);
116116
int tipc_nametbl_init(struct net *net);
117117
void tipc_nametbl_stop(struct net *net);
118118

119-
struct tipc_plist {
120-
struct list_head list;
121-
u32 port;
122-
};
123-
124-
static inline void tipc_plist_init(struct tipc_plist *pl)
125-
{
126-
INIT_LIST_HEAD(&pl->list);
127-
pl->port = 0;
128-
}
129-
130-
void tipc_plist_push(struct tipc_plist *pl, u32 port);
131-
u32 tipc_plist_pop(struct tipc_plist *pl);
119+
bool u32_push(struct list_head *l, u32 value);
120+
u32 u32_pop(struct list_head *l);
121+
bool u32_find(struct list_head *l, u32 value);
122+
bool u32_del(struct list_head *l, u32 value);
123+
void u32_list_purge(struct list_head *l);
124+
int u32_list_len(struct list_head *l);
132125

133126
#endif

net/tipc/socket.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,15 +788,15 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
788788
struct sk_buff_head *inputq)
789789
{
790790
struct tipc_msg *msg;
791-
struct tipc_plist dports;
791+
struct list_head dports;
792792
u32 portid;
793793
u32 scope = TIPC_CLUSTER_SCOPE;
794794
struct sk_buff_head tmpq;
795795
uint hsz;
796796
struct sk_buff *skb, *_skb;
797797

798798
__skb_queue_head_init(&tmpq);
799-
tipc_plist_init(&dports);
799+
INIT_LIST_HEAD(&dports);
800800

801801
skb = tipc_skb_peek(arrvq, &inputq->lock);
802802
for (; skb; skb = tipc_skb_peek(arrvq, &inputq->lock)) {
@@ -810,8 +810,8 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,
810810
tipc_nametbl_mc_translate(net,
811811
msg_nametype(msg), msg_namelower(msg),
812812
msg_nameupper(msg), scope, &dports);
813-
portid = tipc_plist_pop(&dports);
814-
for (; portid; portid = tipc_plist_pop(&dports)) {
813+
portid = u32_pop(&dports);
814+
for (; portid; portid = u32_pop(&dports)) {
815815
_skb = __pskb_copy(skb, hsz, GFP_ATOMIC);
816816
if (_skb) {
817817
msg_set_destport(buf_msg(_skb), portid);

0 commit comments

Comments
 (0)