Commit 30da63a6af1dbf60e6d989faa4b984b1c6c9dfaf
Committed by
Antonio Quartulli
1 parent
f03a13a716
batman-adv: consolidate duplicated primary_if checking code
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de> Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Showing 6 changed files with 57 additions and 91 deletions Side-by-side Diff
net/batman-adv/bridge_loop_avoidance.c
... | ... | @@ -1585,24 +1585,12 @@ |
1585 | 1585 | struct hlist_head *head; |
1586 | 1586 | uint32_t i; |
1587 | 1587 | bool is_own; |
1588 | - int ret = 0; | |
1589 | 1588 | uint8_t *primary_addr; |
1590 | 1589 | |
1591 | - primary_if = batadv_primary_if_get_selected(bat_priv); | |
1592 | - if (!primary_if) { | |
1593 | - ret = seq_printf(seq, | |
1594 | - "BATMAN mesh %s disabled - please specify interfaces to enable it\n", | |
1595 | - net_dev->name); | |
1590 | + primary_if = batadv_seq_print_text_primary_if_get(seq); | |
1591 | + if (!primary_if) | |
1596 | 1592 | goto out; |
1597 | - } | |
1598 | 1593 | |
1599 | - if (primary_if->if_status != BATADV_IF_ACTIVE) { | |
1600 | - ret = seq_printf(seq, | |
1601 | - "BATMAN mesh %s disabled - primary interface not active\n", | |
1602 | - net_dev->name); | |
1603 | - goto out; | |
1604 | - } | |
1605 | - | |
1606 | 1594 | primary_addr = primary_if->net_dev->dev_addr; |
1607 | 1595 | seq_printf(seq, |
1608 | 1596 | "Claims announced for the mesh %s (orig %pM, group id %04x)\n", |
... | ... | @@ -1628,7 +1616,7 @@ |
1628 | 1616 | out: |
1629 | 1617 | if (primary_if) |
1630 | 1618 | batadv_hardif_free_ref(primary_if); |
1631 | - return ret; | |
1619 | + return 0; | |
1632 | 1620 | } |
1633 | 1621 | |
1634 | 1622 | int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset) |
1635 | 1623 | |
1636 | 1624 | |
1637 | 1625 | |
... | ... | @@ -1643,24 +1631,12 @@ |
1643 | 1631 | int secs, msecs; |
1644 | 1632 | uint32_t i; |
1645 | 1633 | bool is_own; |
1646 | - int ret = 0; | |
1647 | 1634 | uint8_t *primary_addr; |
1648 | 1635 | |
1649 | - primary_if = batadv_primary_if_get_selected(bat_priv); | |
1650 | - if (!primary_if) { | |
1651 | - ret = seq_printf(seq, | |
1652 | - "BATMAN mesh %s disabled - please specify interfaces to enable it\n", | |
1653 | - net_dev->name); | |
1636 | + primary_if = batadv_seq_print_text_primary_if_get(seq); | |
1637 | + if (!primary_if) | |
1654 | 1638 | goto out; |
1655 | - } | |
1656 | 1639 | |
1657 | - if (primary_if->if_status != BATADV_IF_ACTIVE) { | |
1658 | - ret = seq_printf(seq, | |
1659 | - "BATMAN mesh %s disabled - primary interface not active\n", | |
1660 | - net_dev->name); | |
1661 | - goto out; | |
1662 | - } | |
1663 | - | |
1664 | 1640 | primary_addr = primary_if->net_dev->dev_addr; |
1665 | 1641 | seq_printf(seq, |
1666 | 1642 | "Backbones announced for the mesh %s (orig %pM, group id %04x)\n", |
... | ... | @@ -1693,6 +1669,6 @@ |
1693 | 1669 | out: |
1694 | 1670 | if (primary_if) |
1695 | 1671 | batadv_hardif_free_ref(primary_if); |
1696 | - return ret; | |
1672 | + return 0; | |
1697 | 1673 | } |
net/batman-adv/gateway_client.c
... | ... | @@ -477,23 +477,12 @@ |
477 | 477 | struct batadv_hard_iface *primary_if; |
478 | 478 | struct batadv_gw_node *gw_node; |
479 | 479 | struct hlist_node *node; |
480 | - int gw_count = 0, ret = 0; | |
480 | + int gw_count = 0; | |
481 | 481 | |
482 | - primary_if = batadv_primary_if_get_selected(bat_priv); | |
483 | - if (!primary_if) { | |
484 | - ret = seq_printf(seq, | |
485 | - "BATMAN mesh %s disabled - please specify interfaces to enable it\n", | |
486 | - net_dev->name); | |
482 | + primary_if = batadv_seq_print_text_primary_if_get(seq); | |
483 | + if (!primary_if) | |
487 | 484 | goto out; |
488 | - } | |
489 | 485 | |
490 | - if (primary_if->if_status != BATADV_IF_ACTIVE) { | |
491 | - ret = seq_printf(seq, | |
492 | - "BATMAN mesh %s disabled - primary interface not active\n", | |
493 | - net_dev->name); | |
494 | - goto out; | |
495 | - } | |
496 | - | |
497 | 486 | seq_printf(seq, |
498 | 487 | " %-12s (%s/%i) %17s [%10s]: gw_class ... [B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n", |
499 | 488 | "Gateway", "#", BATADV_TQ_MAX_VALUE, "Nexthop", "outgoingIF", |
... | ... | @@ -519,7 +508,7 @@ |
519 | 508 | out: |
520 | 509 | if (primary_if) |
521 | 510 | batadv_hardif_free_ref(primary_if); |
522 | - return ret; | |
511 | + return 0; | |
523 | 512 | } |
524 | 513 | |
525 | 514 | static bool batadv_is_type_dhcprequest(struct sk_buff *skb, int header_len) |
net/batman-adv/main.c
... | ... | @@ -188,6 +188,42 @@ |
188 | 188 | return 0; |
189 | 189 | } |
190 | 190 | |
191 | +/** | |
192 | + * batadv_seq_print_text_primary_if_get - called from debugfs table printing | |
193 | + * function that requires the primary interface | |
194 | + * @seq: debugfs table seq_file struct | |
195 | + * | |
196 | + * Returns primary interface if found or NULL otherwise. | |
197 | + */ | |
198 | +struct batadv_hard_iface * | |
199 | +batadv_seq_print_text_primary_if_get(struct seq_file *seq) | |
200 | +{ | |
201 | + struct net_device *net_dev = (struct net_device *)seq->private; | |
202 | + struct batadv_priv *bat_priv = netdev_priv(net_dev); | |
203 | + struct batadv_hard_iface *primary_if; | |
204 | + | |
205 | + primary_if = batadv_primary_if_get_selected(bat_priv); | |
206 | + | |
207 | + if (!primary_if) { | |
208 | + seq_printf(seq, | |
209 | + "BATMAN mesh %s disabled - please specify interfaces to enable it\n", | |
210 | + net_dev->name); | |
211 | + goto out; | |
212 | + } | |
213 | + | |
214 | + if (primary_if->if_status == BATADV_IF_ACTIVE) | |
215 | + goto out; | |
216 | + | |
217 | + seq_printf(seq, | |
218 | + "BATMAN mesh %s disabled - primary interface not active\n", | |
219 | + net_dev->name); | |
220 | + batadv_hardif_free_ref(primary_if); | |
221 | + primary_if = NULL; | |
222 | + | |
223 | +out: | |
224 | + return primary_if; | |
225 | +} | |
226 | + | |
191 | 227 | static int batadv_recv_unhandled_packet(struct sk_buff *skb, |
192 | 228 | struct batadv_hard_iface *recv_if) |
193 | 229 | { |
net/batman-adv/main.h
... | ... | @@ -153,6 +153,8 @@ |
153 | 153 | void batadv_inc_module_count(void); |
154 | 154 | void batadv_dec_module_count(void); |
155 | 155 | int batadv_is_my_mac(const uint8_t *addr); |
156 | +struct batadv_hard_iface * | |
157 | +batadv_seq_print_text_primary_if_get(struct seq_file *seq); | |
156 | 158 | int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev, |
157 | 159 | struct packet_type *ptype, |
158 | 160 | struct net_device *orig_dev); |
net/batman-adv/originator.c
... | ... | @@ -415,24 +415,11 @@ |
415 | 415 | int last_seen_msecs; |
416 | 416 | unsigned long last_seen_jiffies; |
417 | 417 | uint32_t i; |
418 | - int ret = 0; | |
419 | 418 | |
420 | - primary_if = batadv_primary_if_get_selected(bat_priv); | |
421 | - | |
422 | - if (!primary_if) { | |
423 | - ret = seq_printf(seq, | |
424 | - "BATMAN mesh %s disabled - please specify interfaces to enable it\n", | |
425 | - net_dev->name); | |
419 | + primary_if = batadv_seq_print_text_primary_if_get(seq); | |
420 | + if (!primary_if) | |
426 | 421 | goto out; |
427 | - } | |
428 | 422 | |
429 | - if (primary_if->if_status != BATADV_IF_ACTIVE) { | |
430 | - ret = seq_printf(seq, | |
431 | - "BATMAN mesh %s disabled - primary interface not active\n", | |
432 | - net_dev->name); | |
433 | - goto out; | |
434 | - } | |
435 | - | |
436 | 423 | seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n", |
437 | 424 | BATADV_SOURCE_VERSION, primary_if->net_dev->name, |
438 | 425 | primary_if->net_dev->dev_addr, net_dev->name); |
... | ... | @@ -485,7 +472,7 @@ |
485 | 472 | out: |
486 | 473 | if (primary_if) |
487 | 474 | batadv_hardif_free_ref(primary_if); |
488 | - return ret; | |
475 | + return 0; | |
489 | 476 | } |
490 | 477 | |
491 | 478 | static int batadv_orig_node_add_if(struct batadv_orig_node *orig_node, |
net/batman-adv/translation-table.c
... | ... | @@ -434,23 +434,11 @@ |
434 | 434 | struct hlist_node *node; |
435 | 435 | struct hlist_head *head; |
436 | 436 | uint32_t i; |
437 | - int ret = 0; | |
438 | 437 | |
439 | - primary_if = batadv_primary_if_get_selected(bat_priv); | |
440 | - if (!primary_if) { | |
441 | - ret = seq_printf(seq, | |
442 | - "BATMAN mesh %s disabled - please specify interfaces to enable it\n", | |
443 | - net_dev->name); | |
438 | + primary_if = batadv_seq_print_text_primary_if_get(seq); | |
439 | + if (!primary_if) | |
444 | 440 | goto out; |
445 | - } | |
446 | 441 | |
447 | - if (primary_if->if_status != BATADV_IF_ACTIVE) { | |
448 | - ret = seq_printf(seq, | |
449 | - "BATMAN mesh %s disabled - primary interface not active\n", | |
450 | - net_dev->name); | |
451 | - goto out; | |
452 | - } | |
453 | - | |
454 | 442 | seq_printf(seq, |
455 | 443 | "Locally retrieved addresses (from %s) announced via TT (TTVN: %u):\n", |
456 | 444 | net_dev->name, (uint8_t)atomic_read(&bat_priv->tt.vn)); |
... | ... | @@ -479,7 +467,7 @@ |
479 | 467 | out: |
480 | 468 | if (primary_if) |
481 | 469 | batadv_hardif_free_ref(primary_if); |
482 | - return ret; | |
470 | + return 0; | |
483 | 471 | } |
484 | 472 | |
485 | 473 | static void |
486 | 474 | |
487 | 475 | |
488 | 476 | |
... | ... | @@ -842,23 +830,11 @@ |
842 | 830 | struct hlist_node *node; |
843 | 831 | struct hlist_head *head; |
844 | 832 | uint32_t i; |
845 | - int ret = 0; | |
846 | 833 | |
847 | - primary_if = batadv_primary_if_get_selected(bat_priv); | |
848 | - if (!primary_if) { | |
849 | - ret = seq_printf(seq, | |
850 | - "BATMAN mesh %s disabled - please specify interfaces to enable it\n", | |
851 | - net_dev->name); | |
834 | + primary_if = batadv_seq_print_text_primary_if_get(seq); | |
835 | + if (!primary_if) | |
852 | 836 | goto out; |
853 | - } | |
854 | 837 | |
855 | - if (primary_if->if_status != BATADV_IF_ACTIVE) { | |
856 | - ret = seq_printf(seq, | |
857 | - "BATMAN mesh %s disabled - primary interface not active\n", | |
858 | - net_dev->name); | |
859 | - goto out; | |
860 | - } | |
861 | - | |
862 | 838 | seq_printf(seq, |
863 | 839 | "Globally announced TT entries received via the mesh %s\n", |
864 | 840 | net_dev->name); |
... | ... | @@ -881,7 +857,7 @@ |
881 | 857 | out: |
882 | 858 | if (primary_if) |
883 | 859 | batadv_hardif_free_ref(primary_if); |
884 | - return ret; | |
860 | + return 0; | |
885 | 861 | } |
886 | 862 | |
887 | 863 | /* deletes the orig list of a tt_global_entry */ |