hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/dcb/dcbnl.c
....@@ -1,17 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2008-2011, Intel Corporation.
3
- *
4
- * This program is free software; you can redistribute it and/or modify it
5
- * under the terms and conditions of the GNU General Public License,
6
- * version 2, as published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope it will be useful, but WITHOUT
9
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
- * more details.
12
- *
13
- * You should have received a copy of the GNU General Public License along with
14
- * this program; if not, see <http://www.gnu.org/licenses/>.
154 *
165 * Description: Data Center Bridging netlink interface
176 * Author: Lucy Liu <lucy.liu@intel.com>
....@@ -241,12 +230,13 @@
241230 if (!netdev->dcbnl_ops->getpfccfg)
242231 return -EOPNOTSUPP;
243232
244
- ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
245
- tb[DCB_ATTR_PFC_CFG], dcbnl_pfc_up_nest, NULL);
233
+ ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX,
234
+ tb[DCB_ATTR_PFC_CFG],
235
+ dcbnl_pfc_up_nest, NULL);
246236 if (ret)
247237 return ret;
248238
249
- nest = nla_nest_start(skb, DCB_ATTR_PFC_CFG);
239
+ nest = nla_nest_start_noflag(skb, DCB_ATTR_PFC_CFG);
250240 if (!nest)
251241 return -EMSGSIZE;
252242
....@@ -299,12 +289,13 @@
299289 if (!netdev->dcbnl_ops->getcap)
300290 return -EOPNOTSUPP;
301291
302
- ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
303
- dcbnl_cap_nest, NULL);
292
+ ret = nla_parse_nested_deprecated(data, DCB_CAP_ATTR_MAX,
293
+ tb[DCB_ATTR_CAP], dcbnl_cap_nest,
294
+ NULL);
304295 if (ret)
305296 return ret;
306297
307
- nest = nla_nest_start(skb, DCB_ATTR_CAP);
298
+ nest = nla_nest_start_noflag(skb, DCB_ATTR_CAP);
308299 if (!nest)
309300 return -EMSGSIZE;
310301
....@@ -343,12 +334,13 @@
343334 if (!netdev->dcbnl_ops->getnumtcs)
344335 return -EOPNOTSUPP;
345336
346
- ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
347
- dcbnl_numtcs_nest, NULL);
337
+ ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX,
338
+ tb[DCB_ATTR_NUMTCS],
339
+ dcbnl_numtcs_nest, NULL);
348340 if (ret)
349341 return ret;
350342
351
- nest = nla_nest_start(skb, DCB_ATTR_NUMTCS);
343
+ nest = nla_nest_start_noflag(skb, DCB_ATTR_NUMTCS);
352344 if (!nest)
353345 return -EMSGSIZE;
354346
....@@ -388,8 +380,9 @@
388380 if (!netdev->dcbnl_ops->setnumtcs)
389381 return -EOPNOTSUPP;
390382
391
- ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
392
- dcbnl_numtcs_nest, NULL);
383
+ ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX,
384
+ tb[DCB_ATTR_NUMTCS],
385
+ dcbnl_numtcs_nest, NULL);
393386 if (ret)
394387 return ret;
395388
....@@ -447,8 +440,9 @@
447440 if (!tb[DCB_ATTR_APP])
448441 return -EINVAL;
449442
450
- ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
451
- dcbnl_app_nest, NULL);
443
+ ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX,
444
+ tb[DCB_ATTR_APP], dcbnl_app_nest,
445
+ NULL);
452446 if (ret)
453447 return ret;
454448
....@@ -479,7 +473,7 @@
479473 up = dcb_getapp(netdev, &app);
480474 }
481475
482
- app_nest = nla_nest_start(skb, DCB_ATTR_APP);
476
+ app_nest = nla_nest_start_noflag(skb, DCB_ATTR_APP);
483477 if (!app_nest)
484478 return -EMSGSIZE;
485479
....@@ -515,8 +509,9 @@
515509 if (!tb[DCB_ATTR_APP])
516510 return -EINVAL;
517511
518
- ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
519
- dcbnl_app_nest, NULL);
512
+ ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX,
513
+ tb[DCB_ATTR_APP], dcbnl_app_nest,
514
+ NULL);
520515 if (ret)
521516 return ret;
522517
....@@ -573,12 +568,13 @@
573568 !netdev->dcbnl_ops->getpgbwgcfgrx)
574569 return -EOPNOTSUPP;
575570
576
- ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX, tb[DCB_ATTR_PG_CFG],
577
- dcbnl_pg_nest, NULL);
571
+ ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX,
572
+ tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest,
573
+ NULL);
578574 if (ret)
579575 return ret;
580576
581
- pg_nest = nla_nest_start(skb, DCB_ATTR_PG_CFG);
577
+ pg_nest = nla_nest_start_noflag(skb, DCB_ATTR_PG_CFG);
582578 if (!pg_nest)
583579 return -EMSGSIZE;
584580
....@@ -593,12 +589,13 @@
593589 data = pg_tb[DCB_PG_ATTR_TC_ALL];
594590 else
595591 data = pg_tb[i];
596
- ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX, data,
597
- dcbnl_tc_param_nest, NULL);
592
+ ret = nla_parse_nested_deprecated(param_tb,
593
+ DCB_TC_ATTR_PARAM_MAX, data,
594
+ dcbnl_tc_param_nest, NULL);
598595 if (ret)
599596 goto err_pg;
600597
601
- param_nest = nla_nest_start(skb, i);
598
+ param_nest = nla_nest_start_noflag(skb, i);
602599 if (!param_nest)
603600 goto err_pg;
604601
....@@ -730,8 +727,9 @@
730727 if (!netdev->dcbnl_ops->setpfccfg)
731728 return -EOPNOTSUPP;
732729
733
- ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
734
- tb[DCB_ATTR_PFC_CFG], dcbnl_pfc_up_nest, NULL);
730
+ ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX,
731
+ tb[DCB_ATTR_PFC_CFG],
732
+ dcbnl_pfc_up_nest, NULL);
735733 if (ret)
736734 return ret;
737735
....@@ -786,8 +784,9 @@
786784 !netdev->dcbnl_ops->setpgbwgcfgrx)
787785 return -EOPNOTSUPP;
788786
789
- ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX, tb[DCB_ATTR_PG_CFG],
790
- dcbnl_pg_nest, NULL);
787
+ ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX,
788
+ tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest,
789
+ NULL);
791790 if (ret)
792791 return ret;
793792
....@@ -795,8 +794,10 @@
795794 if (!pg_tb[i])
796795 continue;
797796
798
- ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
799
- pg_tb[i], dcbnl_tc_param_nest, NULL);
797
+ ret = nla_parse_nested_deprecated(param_tb,
798
+ DCB_TC_ATTR_PARAM_MAX,
799
+ pg_tb[i],
800
+ dcbnl_tc_param_nest, NULL);
800801 if (ret)
801802 return ret;
802803
....@@ -884,12 +885,13 @@
884885 !netdev->dcbnl_ops->getbcncfg)
885886 return -EOPNOTSUPP;
886887
887
- ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX, tb[DCB_ATTR_BCN],
888
- dcbnl_bcn_nest, NULL);
888
+ ret = nla_parse_nested_deprecated(bcn_tb, DCB_BCN_ATTR_MAX,
889
+ tb[DCB_ATTR_BCN], dcbnl_bcn_nest,
890
+ NULL);
889891 if (ret)
890892 return ret;
891893
892
- bcn_nest = nla_nest_start(skb, DCB_ATTR_BCN);
894
+ bcn_nest = nla_nest_start_noflag(skb, DCB_ATTR_BCN);
893895 if (!bcn_nest)
894896 return -EMSGSIZE;
895897
....@@ -943,8 +945,9 @@
943945 !netdev->dcbnl_ops->setbcnrp)
944946 return -EOPNOTSUPP;
945947
946
- ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX, tb[DCB_ATTR_BCN],
947
- dcbnl_pfc_up_nest, NULL);
948
+ ret = nla_parse_nested_deprecated(data, DCB_BCN_ATTR_MAX,
949
+ tb[DCB_ATTR_BCN], dcbnl_bcn_nest,
950
+ NULL);
948951 if (ret)
949952 return ret;
950953
....@@ -1002,7 +1005,7 @@
10021005 */
10031006 err = -EMSGSIZE;
10041007
1005
- app = nla_nest_start(skb, app_nested_type);
1008
+ app = nla_nest_start_noflag(skb, app_nested_type);
10061009 if (!app)
10071010 goto nla_put_failure;
10081011
....@@ -1036,7 +1039,7 @@
10361039 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
10371040 return -EMSGSIZE;
10381041
1039
- ieee = nla_nest_start(skb, DCB_ATTR_IEEE);
1042
+ ieee = nla_nest_start_noflag(skb, DCB_ATTR_IEEE);
10401043 if (!ieee)
10411044 return -EMSGSIZE;
10421045
....@@ -1106,7 +1109,7 @@
11061109 return -EMSGSIZE;
11071110 }
11081111
1109
- app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE);
1112
+ app = nla_nest_start_noflag(skb, DCB_ATTR_IEEE_APP_TABLE);
11101113 if (!app)
11111114 return -EMSGSIZE;
11121115
....@@ -1174,13 +1177,13 @@
11741177 u8 pgid, up_map, prio, tc_pct;
11751178 const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
11761179 int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG;
1177
- struct nlattr *pg = nla_nest_start(skb, i);
1180
+ struct nlattr *pg = nla_nest_start_noflag(skb, i);
11781181
11791182 if (!pg)
11801183 return -EMSGSIZE;
11811184
11821185 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
1183
- struct nlattr *tc_nest = nla_nest_start(skb, i);
1186
+ struct nlattr *tc_nest = nla_nest_start_noflag(skb, i);
11841187
11851188 if (!tc_nest)
11861189 return -EMSGSIZE;
....@@ -1231,7 +1234,7 @@
12311234
12321235 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
12331236 goto nla_put_failure;
1234
- cee = nla_nest_start(skb, DCB_ATTR_CEE);
1237
+ cee = nla_nest_start_noflag(skb, DCB_ATTR_CEE);
12351238 if (!cee)
12361239 goto nla_put_failure;
12371240
....@@ -1250,7 +1253,8 @@
12501253
12511254 /* local pfc */
12521255 if (ops->getpfccfg) {
1253
- struct nlattr *pfc_nest = nla_nest_start(skb, DCB_ATTR_CEE_PFC);
1256
+ struct nlattr *pfc_nest = nla_nest_start_noflag(skb,
1257
+ DCB_ATTR_CEE_PFC);
12541258
12551259 if (!pfc_nest)
12561260 goto nla_put_failure;
....@@ -1265,14 +1269,14 @@
12651269
12661270 /* local app */
12671271 spin_lock_bh(&dcb_lock);
1268
- app = nla_nest_start(skb, DCB_ATTR_CEE_APP_TABLE);
1272
+ app = nla_nest_start_noflag(skb, DCB_ATTR_CEE_APP_TABLE);
12691273 if (!app)
12701274 goto dcb_unlock;
12711275
12721276 list_for_each_entry(itr, &dcb_app_list, list) {
12731277 if (itr->ifindex == netdev->ifindex) {
1274
- struct nlattr *app_nest = nla_nest_start(skb,
1275
- DCB_ATTR_APP);
1278
+ struct nlattr *app_nest = nla_nest_start_noflag(skb,
1279
+ DCB_ATTR_APP);
12761280 if (!app_nest)
12771281 goto dcb_unlock;
12781282
....@@ -1305,7 +1309,8 @@
13051309
13061310 /* features flags */
13071311 if (ops->getfeatcfg) {
1308
- struct nlattr *feat = nla_nest_start(skb, DCB_ATTR_CEE_FEAT);
1312
+ struct nlattr *feat = nla_nest_start_noflag(skb,
1313
+ DCB_ATTR_CEE_FEAT);
13091314 if (!feat)
13101315 goto nla_put_failure;
13111316
....@@ -1430,8 +1435,9 @@
14301435 if (!tb[DCB_ATTR_IEEE])
14311436 return -EINVAL;
14321437
1433
- err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX, tb[DCB_ATTR_IEEE],
1434
- dcbnl_ieee_policy, NULL);
1438
+ err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX,
1439
+ tb[DCB_ATTR_IEEE],
1440
+ dcbnl_ieee_policy, NULL);
14351441 if (err)
14361442 return err;
14371443
....@@ -1537,8 +1543,9 @@
15371543 if (!tb[DCB_ATTR_IEEE])
15381544 return -EINVAL;
15391545
1540
- err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX, tb[DCB_ATTR_IEEE],
1541
- dcbnl_ieee_policy, NULL);
1546
+ err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX,
1547
+ tb[DCB_ATTR_IEEE],
1548
+ dcbnl_ieee_policy, NULL);
15421549 if (err)
15431550 return err;
15441551
....@@ -1610,12 +1617,13 @@
16101617 if (!tb[DCB_ATTR_FEATCFG])
16111618 return -EINVAL;
16121619
1613
- ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX,
1614
- tb[DCB_ATTR_FEATCFG], dcbnl_featcfg_nest, NULL);
1620
+ ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX,
1621
+ tb[DCB_ATTR_FEATCFG],
1622
+ dcbnl_featcfg_nest, NULL);
16151623 if (ret)
16161624 return ret;
16171625
1618
- nest = nla_nest_start(skb, DCB_ATTR_FEATCFG);
1626
+ nest = nla_nest_start_noflag(skb, DCB_ATTR_FEATCFG);
16191627 if (!nest)
16201628 return -EMSGSIZE;
16211629
....@@ -1654,8 +1662,9 @@
16541662 if (!tb[DCB_ATTR_FEATCFG])
16551663 return -EINVAL;
16561664
1657
- ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX,
1658
- tb[DCB_ATTR_FEATCFG], dcbnl_featcfg_nest, NULL);
1665
+ ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX,
1666
+ tb[DCB_ATTR_FEATCFG],
1667
+ dcbnl_featcfg_nest, NULL);
16591668
16601669 if (ret)
16611670 goto err;
....@@ -1735,7 +1744,7 @@
17351744 struct net_device *netdev;
17361745 struct dcbmsg *dcb = nlmsg_data(nlh);
17371746 struct nlattr *tb[DCB_ATTR_MAX + 1];
1738
- u32 portid = skb ? NETLINK_CB(skb).portid : 0;
1747
+ u32 portid = NETLINK_CB(skb).portid;
17391748 int ret = -EINVAL;
17401749 struct sk_buff *reply_skb;
17411750 struct nlmsghdr *reply_nlh = NULL;
....@@ -1744,8 +1753,8 @@
17441753 if ((nlh->nlmsg_type == RTM_SETDCB) && !netlink_capable(skb, CAP_NET_ADMIN))
17451754 return -EPERM;
17461755
1747
- ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
1748
- dcbnl_rtnl_policy, extack);
1756
+ ret = nlmsg_parse_deprecated(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
1757
+ dcbnl_rtnl_policy, extack);
17491758 if (ret < 0)
17501759 return ret;
17511760
....@@ -2054,10 +2063,54 @@
20542063 }
20552064 EXPORT_SYMBOL(dcb_ieee_getapp_default_prio_mask);
20562065
2066
+static void dcbnl_flush_dev(struct net_device *dev)
2067
+{
2068
+ struct dcb_app_type *itr, *tmp;
2069
+
2070
+ spin_lock_bh(&dcb_lock);
2071
+
2072
+ list_for_each_entry_safe(itr, tmp, &dcb_app_list, list) {
2073
+ if (itr->ifindex == dev->ifindex) {
2074
+ list_del(&itr->list);
2075
+ kfree(itr);
2076
+ }
2077
+ }
2078
+
2079
+ spin_unlock_bh(&dcb_lock);
2080
+}
2081
+
2082
+static int dcbnl_netdevice_event(struct notifier_block *nb,
2083
+ unsigned long event, void *ptr)
2084
+{
2085
+ struct net_device *dev = netdev_notifier_info_to_dev(ptr);
2086
+
2087
+ switch (event) {
2088
+ case NETDEV_UNREGISTER:
2089
+ if (!dev->dcbnl_ops)
2090
+ return NOTIFY_DONE;
2091
+
2092
+ dcbnl_flush_dev(dev);
2093
+
2094
+ return NOTIFY_OK;
2095
+ default:
2096
+ return NOTIFY_DONE;
2097
+ }
2098
+}
2099
+
2100
+static struct notifier_block dcbnl_nb __read_mostly = {
2101
+ .notifier_call = dcbnl_netdevice_event,
2102
+};
2103
+
20572104 static int __init dcbnl_init(void)
20582105 {
2106
+ int err;
2107
+
20592108 INIT_LIST_HEAD(&dcb_app_list);
20602109
2110
+ err = register_netdevice_notifier(&dcbnl_nb);
2111
+ if (err)
2112
+ return err;
2113
+
20612114 rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, 0);
20622115 rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, 0);
20632116