Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dcb: add new common function for set/del of app/rewr entries

In preparation for DCB rewrite. Add a new function for setting and
deleting both app and rewrite entries. Moving this into a separate
function reduces duplicate code, as both type of entries requires the
same set of checks. The function will now iterate through a configurable
nested attribute (app or rewrite attr), validate each attribute and call
the appropriate set- or delete function.

Note that this function always checks for nla_len(attr_itr) <
sizeof(struct dcb_app), which was only done in dcbnl_ieee_set and not in
dcbnl_ieee_del prior to this patch. This means, that any userspace tool
that used to shove in data < sizeof(struct dcb_app) would now receive
-ERANGE.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Daniel Machon and committed by
David S. Miller
30568334 34b7074d

+45 -55
+45 -55
net/dcb/dcbnl.c
··· 1099 1099 return err; 1100 1100 } 1101 1101 1102 + /* Set or delete APP table or rewrite table entries. The APP struct is validated 1103 + * and the appropriate callback function is called. 1104 + */ 1105 + static int dcbnl_app_table_setdel(struct nlattr *attr, 1106 + struct net_device *netdev, 1107 + int (*setdel)(struct net_device *dev, 1108 + struct dcb_app *app)) 1109 + { 1110 + struct dcb_app *app_data; 1111 + enum ieee_attrs_app type; 1112 + struct nlattr *attr_itr; 1113 + int rem, err; 1114 + 1115 + nla_for_each_nested(attr_itr, attr, rem) { 1116 + type = nla_type(attr_itr); 1117 + 1118 + if (!dcbnl_app_attr_type_validate(type)) 1119 + continue; 1120 + 1121 + if (nla_len(attr_itr) < sizeof(struct dcb_app)) 1122 + return -ERANGE; 1123 + 1124 + app_data = nla_data(attr_itr); 1125 + 1126 + if (!dcbnl_app_selector_validate(type, app_data->selector)) 1127 + return -EINVAL; 1128 + 1129 + err = setdel(netdev, app_data); 1130 + if (err) 1131 + return err; 1132 + } 1133 + 1134 + return 0; 1135 + } 1136 + 1102 1137 /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */ 1103 1138 static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) 1104 1139 { ··· 1603 1568 } 1604 1569 1605 1570 if (ieee[DCB_ATTR_IEEE_APP_TABLE]) { 1606 - struct nlattr *attr; 1607 - int rem; 1608 - 1609 - nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) { 1610 - enum ieee_attrs_app type = nla_type(attr); 1611 - struct dcb_app *app_data; 1612 - 1613 - if (!dcbnl_app_attr_type_validate(type)) 1614 - continue; 1615 - 1616 - if (nla_len(attr) < sizeof(struct dcb_app)) { 1617 - err = -ERANGE; 1618 - goto err; 1619 - } 1620 - 1621 - app_data = nla_data(attr); 1622 - 1623 - if (!dcbnl_app_selector_validate(type, 1624 - app_data->selector)) { 1625 - err = -EINVAL; 1626 - goto err; 1627 - } 1628 - 1629 - if (ops->ieee_setapp) 1630 - err = ops->ieee_setapp(netdev, app_data); 1631 - else 1632 - err = dcb_ieee_setapp(netdev, app_data); 1633 - if (err) 1634 - goto err; 1635 - } 1571 + err = dcbnl_app_table_setdel(ieee[DCB_ATTR_IEEE_APP_TABLE], 1572 + netdev, ops->ieee_setapp ?: 1573 + dcb_ieee_setapp); 1574 + if (err) 1575 + goto err; 1636 1576 } 1637 1577 1638 1578 if (ieee[DCB_ATTR_DCB_APP_TRUST_TABLE]) { ··· 1694 1684 return err; 1695 1685 1696 1686 if (ieee[DCB_ATTR_IEEE_APP_TABLE]) { 1697 - struct nlattr *attr; 1698 - int rem; 1699 - 1700 - nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) { 1701 - enum ieee_attrs_app type = nla_type(attr); 1702 - struct dcb_app *app_data; 1703 - 1704 - if (!dcbnl_app_attr_type_validate(type)) 1705 - continue; 1706 - 1707 - app_data = nla_data(attr); 1708 - 1709 - if (!dcbnl_app_selector_validate(type, 1710 - app_data->selector)) { 1711 - err = -EINVAL; 1712 - goto err; 1713 - } 1714 - 1715 - if (ops->ieee_delapp) 1716 - err = ops->ieee_delapp(netdev, app_data); 1717 - else 1718 - err = dcb_ieee_delapp(netdev, app_data); 1719 - if (err) 1720 - goto err; 1721 - } 1687 + err = dcbnl_app_table_setdel(ieee[DCB_ATTR_IEEE_APP_TABLE], 1688 + netdev, ops->ieee_delapp ?: 1689 + dcb_ieee_delapp); 1690 + if (err) 1691 + goto err; 1722 1692 } 1723 1693 1724 1694 err: