br_cfm_netlink.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #include <net/genetlink.h>
  3. #include "br_private.h"
  4. #include "br_private_cfm.h"
  5. static const struct nla_policy
  6. br_cfm_mep_create_policy[IFLA_BRIDGE_CFM_MEP_CREATE_MAX + 1] = {
  7. [IFLA_BRIDGE_CFM_MEP_CREATE_UNSPEC] = { .type = NLA_REJECT },
  8. [IFLA_BRIDGE_CFM_MEP_CREATE_INSTANCE] = { .type = NLA_U32 },
  9. [IFLA_BRIDGE_CFM_MEP_CREATE_DOMAIN] = { .type = NLA_U32 },
  10. [IFLA_BRIDGE_CFM_MEP_CREATE_DIRECTION] = { .type = NLA_U32 },
  11. [IFLA_BRIDGE_CFM_MEP_CREATE_IFINDEX] = { .type = NLA_U32 },
  12. };
  13. static const struct nla_policy
  14. br_cfm_mep_delete_policy[IFLA_BRIDGE_CFM_MEP_DELETE_MAX + 1] = {
  15. [IFLA_BRIDGE_CFM_MEP_DELETE_UNSPEC] = { .type = NLA_REJECT },
  16. [IFLA_BRIDGE_CFM_MEP_DELETE_INSTANCE] = { .type = NLA_U32 },
  17. };
  18. static const struct nla_policy
  19. br_cfm_mep_config_policy[IFLA_BRIDGE_CFM_MEP_CONFIG_MAX + 1] = {
  20. [IFLA_BRIDGE_CFM_MEP_CONFIG_UNSPEC] = { .type = NLA_REJECT },
  21. [IFLA_BRIDGE_CFM_MEP_CONFIG_INSTANCE] = { .type = NLA_U32 },
  22. [IFLA_BRIDGE_CFM_MEP_CONFIG_UNICAST_MAC] = NLA_POLICY_ETH_ADDR,
  23. [IFLA_BRIDGE_CFM_MEP_CONFIG_MDLEVEL] = NLA_POLICY_MAX(NLA_U32, 7),
  24. [IFLA_BRIDGE_CFM_MEP_CONFIG_MEPID] = NLA_POLICY_MAX(NLA_U32, 0x1FFF),
  25. };
  26. static const struct nla_policy
  27. br_cfm_cc_config_policy[IFLA_BRIDGE_CFM_CC_CONFIG_MAX + 1] = {
  28. [IFLA_BRIDGE_CFM_CC_CONFIG_UNSPEC] = { .type = NLA_REJECT },
  29. [IFLA_BRIDGE_CFM_CC_CONFIG_INSTANCE] = { .type = NLA_U32 },
  30. [IFLA_BRIDGE_CFM_CC_CONFIG_ENABLE] = { .type = NLA_U32 },
  31. [IFLA_BRIDGE_CFM_CC_CONFIG_EXP_INTERVAL] = { .type = NLA_U32 },
  32. [IFLA_BRIDGE_CFM_CC_CONFIG_EXP_MAID] = {
  33. .type = NLA_BINARY, .len = CFM_MAID_LENGTH },
  34. };
  35. static const struct nla_policy
  36. br_cfm_cc_peer_mep_policy[IFLA_BRIDGE_CFM_CC_PEER_MEP_MAX + 1] = {
  37. [IFLA_BRIDGE_CFM_CC_PEER_MEP_UNSPEC] = { .type = NLA_REJECT },
  38. [IFLA_BRIDGE_CFM_CC_PEER_MEP_INSTANCE] = { .type = NLA_U32 },
  39. [IFLA_BRIDGE_CFM_CC_PEER_MEPID] = NLA_POLICY_MAX(NLA_U32, 0x1FFF),
  40. };
  41. static const struct nla_policy
  42. br_cfm_cc_rdi_policy[IFLA_BRIDGE_CFM_CC_RDI_MAX + 1] = {
  43. [IFLA_BRIDGE_CFM_CC_RDI_UNSPEC] = { .type = NLA_REJECT },
  44. [IFLA_BRIDGE_CFM_CC_RDI_INSTANCE] = { .type = NLA_U32 },
  45. [IFLA_BRIDGE_CFM_CC_RDI_RDI] = { .type = NLA_U32 },
  46. };
  47. static const struct nla_policy
  48. br_cfm_cc_ccm_tx_policy[IFLA_BRIDGE_CFM_CC_CCM_TX_MAX + 1] = {
  49. [IFLA_BRIDGE_CFM_CC_CCM_TX_UNSPEC] = { .type = NLA_REJECT },
  50. [IFLA_BRIDGE_CFM_CC_CCM_TX_INSTANCE] = { .type = NLA_U32 },
  51. [IFLA_BRIDGE_CFM_CC_CCM_TX_DMAC] = NLA_POLICY_ETH_ADDR,
  52. [IFLA_BRIDGE_CFM_CC_CCM_TX_SEQ_NO_UPDATE] = { .type = NLA_U32 },
  53. [IFLA_BRIDGE_CFM_CC_CCM_TX_PERIOD] = { .type = NLA_U32 },
  54. [IFLA_BRIDGE_CFM_CC_CCM_TX_IF_TLV] = { .type = NLA_U32 },
  55. [IFLA_BRIDGE_CFM_CC_CCM_TX_IF_TLV_VALUE] = { .type = NLA_U8 },
  56. [IFLA_BRIDGE_CFM_CC_CCM_TX_PORT_TLV] = { .type = NLA_U32 },
  57. [IFLA_BRIDGE_CFM_CC_CCM_TX_PORT_TLV_VALUE] = { .type = NLA_U8 },
  58. };
  59. static const struct nla_policy
  60. br_cfm_policy[IFLA_BRIDGE_CFM_MAX + 1] = {
  61. [IFLA_BRIDGE_CFM_UNSPEC] = { .type = NLA_REJECT },
  62. [IFLA_BRIDGE_CFM_MEP_CREATE] =
  63. NLA_POLICY_NESTED(br_cfm_mep_create_policy),
  64. [IFLA_BRIDGE_CFM_MEP_DELETE] =
  65. NLA_POLICY_NESTED(br_cfm_mep_delete_policy),
  66. [IFLA_BRIDGE_CFM_MEP_CONFIG] =
  67. NLA_POLICY_NESTED(br_cfm_mep_config_policy),
  68. [IFLA_BRIDGE_CFM_CC_CONFIG] =
  69. NLA_POLICY_NESTED(br_cfm_cc_config_policy),
  70. [IFLA_BRIDGE_CFM_CC_PEER_MEP_ADD] =
  71. NLA_POLICY_NESTED(br_cfm_cc_peer_mep_policy),
  72. [IFLA_BRIDGE_CFM_CC_PEER_MEP_REMOVE] =
  73. NLA_POLICY_NESTED(br_cfm_cc_peer_mep_policy),
  74. [IFLA_BRIDGE_CFM_CC_RDI] =
  75. NLA_POLICY_NESTED(br_cfm_cc_rdi_policy),
  76. [IFLA_BRIDGE_CFM_CC_CCM_TX] =
  77. NLA_POLICY_NESTED(br_cfm_cc_ccm_tx_policy),
  78. };
  79. static int br_mep_create_parse(struct net_bridge *br, struct nlattr *attr,
  80. struct netlink_ext_ack *extack)
  81. {
  82. struct nlattr *tb[IFLA_BRIDGE_CFM_MEP_CREATE_MAX + 1];
  83. struct br_cfm_mep_create create;
  84. u32 instance;
  85. int err;
  86. err = nla_parse_nested(tb, IFLA_BRIDGE_CFM_MEP_CREATE_MAX, attr,
  87. br_cfm_mep_create_policy, extack);
  88. if (err)
  89. return err;
  90. if (!tb[IFLA_BRIDGE_CFM_MEP_CREATE_INSTANCE]) {
  91. NL_SET_ERR_MSG_MOD(extack, "Missing INSTANCE attribute");
  92. return -EINVAL;
  93. }
  94. if (!tb[IFLA_BRIDGE_CFM_MEP_CREATE_DOMAIN]) {
  95. NL_SET_ERR_MSG_MOD(extack, "Missing DOMAIN attribute");
  96. return -EINVAL;
  97. }
  98. if (!tb[IFLA_BRIDGE_CFM_MEP_CREATE_DIRECTION]) {
  99. NL_SET_ERR_MSG_MOD(extack, "Missing DIRECTION attribute");
  100. return -EINVAL;
  101. }
  102. if (!tb[IFLA_BRIDGE_CFM_MEP_CREATE_IFINDEX]) {
  103. NL_SET_ERR_MSG_MOD(extack, "Missing IFINDEX attribute");
  104. return -EINVAL;
  105. }
  106. memset(&create, 0, sizeof(create));
  107. instance = nla_get_u32(tb[IFLA_BRIDGE_CFM_MEP_CREATE_INSTANCE]);
  108. create.domain = nla_get_u32(tb[IFLA_BRIDGE_CFM_MEP_CREATE_DOMAIN]);
  109. create.direction = nla_get_u32(tb[IFLA_BRIDGE_CFM_MEP_CREATE_DIRECTION]);
  110. create.ifindex = nla_get_u32(tb[IFLA_BRIDGE_CFM_MEP_CREATE_IFINDEX]);
  111. return br_cfm_mep_create(br, instance, &create, extack);
  112. }
  113. static int br_mep_delete_parse(struct net_bridge *br, struct nlattr *attr,
  114. struct netlink_ext_ack *extack)
  115. {
  116. struct nlattr *tb[IFLA_BRIDGE_CFM_MEP_DELETE_MAX + 1];
  117. u32 instance;
  118. int err;
  119. err = nla_parse_nested(tb, IFLA_BRIDGE_CFM_MEP_DELETE_MAX, attr,
  120. br_cfm_mep_delete_policy, extack);
  121. if (err)
  122. return err;
  123. if (!tb[IFLA_BRIDGE_CFM_MEP_DELETE_INSTANCE]) {
  124. NL_SET_ERR_MSG_MOD(extack,
  125. "Missing INSTANCE attribute");
  126. return -EINVAL;
  127. }
  128. instance = nla_get_u32(tb[IFLA_BRIDGE_CFM_MEP_DELETE_INSTANCE]);
  129. return br_cfm_mep_delete(br, instance, extack);
  130. }
  131. static int br_mep_config_parse(struct net_bridge *br, struct nlattr *attr,
  132. struct netlink_ext_ack *extack)
  133. {
  134. struct nlattr *tb[IFLA_BRIDGE_CFM_MEP_CONFIG_MAX + 1];
  135. struct br_cfm_mep_config config;
  136. u32 instance;
  137. int err;
  138. err = nla_parse_nested(tb, IFLA_BRIDGE_CFM_MEP_CONFIG_MAX, attr,
  139. br_cfm_mep_config_policy, extack);
  140. if (err)
  141. return err;
  142. if (!tb[IFLA_BRIDGE_CFM_MEP_CONFIG_INSTANCE]) {
  143. NL_SET_ERR_MSG_MOD(extack, "Missing INSTANCE attribute");
  144. return -EINVAL;
  145. }
  146. if (!tb[IFLA_BRIDGE_CFM_MEP_CONFIG_UNICAST_MAC]) {
  147. NL_SET_ERR_MSG_MOD(extack, "Missing UNICAST_MAC attribute");
  148. return -EINVAL;
  149. }
  150. if (!tb[IFLA_BRIDGE_CFM_MEP_CONFIG_MDLEVEL]) {
  151. NL_SET_ERR_MSG_MOD(extack, "Missing MDLEVEL attribute");
  152. return -EINVAL;
  153. }
  154. if (!tb[IFLA_BRIDGE_CFM_MEP_CONFIG_MEPID]) {
  155. NL_SET_ERR_MSG_MOD(extack, "Missing MEPID attribute");
  156. return -EINVAL;
  157. }
  158. memset(&config, 0, sizeof(config));
  159. instance = nla_get_u32(tb[IFLA_BRIDGE_CFM_MEP_CONFIG_INSTANCE]);
  160. nla_memcpy(&config.unicast_mac.addr,
  161. tb[IFLA_BRIDGE_CFM_MEP_CONFIG_UNICAST_MAC],
  162. sizeof(config.unicast_mac.addr));
  163. config.mdlevel = nla_get_u32(tb[IFLA_BRIDGE_CFM_MEP_CONFIG_MDLEVEL]);
  164. config.mepid = nla_get_u32(tb[IFLA_BRIDGE_CFM_MEP_CONFIG_MEPID]);
  165. return br_cfm_mep_config_set(br, instance, &config, extack);
  166. }
  167. static int br_cc_config_parse(struct net_bridge *br, struct nlattr *attr,
  168. struct netlink_ext_ack *extack)
  169. {
  170. struct nlattr *tb[IFLA_BRIDGE_CFM_CC_CONFIG_MAX + 1];
  171. struct br_cfm_cc_config config;
  172. u32 instance;
  173. int err;
  174. err = nla_parse_nested(tb, IFLA_BRIDGE_CFM_CC_CONFIG_MAX, attr,
  175. br_cfm_cc_config_policy, extack);
  176. if (err)
  177. return err;
  178. if (!tb[IFLA_BRIDGE_CFM_CC_CONFIG_INSTANCE]) {
  179. NL_SET_ERR_MSG_MOD(extack, "Missing INSTANCE attribute");
  180. return -EINVAL;
  181. }
  182. if (!tb[IFLA_BRIDGE_CFM_CC_CONFIG_ENABLE]) {
  183. NL_SET_ERR_MSG_MOD(extack, "Missing ENABLE attribute");
  184. return -EINVAL;
  185. }
  186. if (!tb[IFLA_BRIDGE_CFM_CC_CONFIG_EXP_INTERVAL]) {
  187. NL_SET_ERR_MSG_MOD(extack, "Missing INTERVAL attribute");
  188. return -EINVAL;
  189. }
  190. if (!tb[IFLA_BRIDGE_CFM_CC_CONFIG_EXP_MAID]) {
  191. NL_SET_ERR_MSG_MOD(extack, "Missing MAID attribute");
  192. return -EINVAL;
  193. }
  194. memset(&config, 0, sizeof(config));
  195. instance = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_CONFIG_INSTANCE]);
  196. config.enable = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_CONFIG_ENABLE]);
  197. config.exp_interval = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_CONFIG_EXP_INTERVAL]);
  198. nla_memcpy(&config.exp_maid.data, tb[IFLA_BRIDGE_CFM_CC_CONFIG_EXP_MAID],
  199. sizeof(config.exp_maid.data));
  200. return br_cfm_cc_config_set(br, instance, &config, extack);
  201. }
  202. static int br_cc_peer_mep_add_parse(struct net_bridge *br, struct nlattr *attr,
  203. struct netlink_ext_ack *extack)
  204. {
  205. struct nlattr *tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_MAX + 1];
  206. u32 instance, peer_mep_id;
  207. int err;
  208. err = nla_parse_nested(tb, IFLA_BRIDGE_CFM_CC_PEER_MEP_MAX, attr,
  209. br_cfm_cc_peer_mep_policy, extack);
  210. if (err)
  211. return err;
  212. if (!tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_INSTANCE]) {
  213. NL_SET_ERR_MSG_MOD(extack, "Missing INSTANCE attribute");
  214. return -EINVAL;
  215. }
  216. if (!tb[IFLA_BRIDGE_CFM_CC_PEER_MEPID]) {
  217. NL_SET_ERR_MSG_MOD(extack, "Missing PEER_MEP_ID attribute");
  218. return -EINVAL;
  219. }
  220. instance = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_INSTANCE]);
  221. peer_mep_id = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_PEER_MEPID]);
  222. return br_cfm_cc_peer_mep_add(br, instance, peer_mep_id, extack);
  223. }
  224. static int br_cc_peer_mep_remove_parse(struct net_bridge *br, struct nlattr *attr,
  225. struct netlink_ext_ack *extack)
  226. {
  227. struct nlattr *tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_MAX + 1];
  228. u32 instance, peer_mep_id;
  229. int err;
  230. err = nla_parse_nested(tb, IFLA_BRIDGE_CFM_CC_PEER_MEP_MAX, attr,
  231. br_cfm_cc_peer_mep_policy, extack);
  232. if (err)
  233. return err;
  234. if (!tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_INSTANCE]) {
  235. NL_SET_ERR_MSG_MOD(extack, "Missing INSTANCE attribute");
  236. return -EINVAL;
  237. }
  238. if (!tb[IFLA_BRIDGE_CFM_CC_PEER_MEPID]) {
  239. NL_SET_ERR_MSG_MOD(extack, "Missing PEER_MEP_ID attribute");
  240. return -EINVAL;
  241. }
  242. instance = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_INSTANCE]);
  243. peer_mep_id = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_PEER_MEPID]);
  244. return br_cfm_cc_peer_mep_remove(br, instance, peer_mep_id, extack);
  245. }
  246. static int br_cc_rdi_parse(struct net_bridge *br, struct nlattr *attr,
  247. struct netlink_ext_ack *extack)
  248. {
  249. struct nlattr *tb[IFLA_BRIDGE_CFM_CC_RDI_MAX + 1];
  250. u32 instance, rdi;
  251. int err;
  252. err = nla_parse_nested(tb, IFLA_BRIDGE_CFM_CC_RDI_MAX, attr,
  253. br_cfm_cc_rdi_policy, extack);
  254. if (err)
  255. return err;
  256. if (!tb[IFLA_BRIDGE_CFM_CC_RDI_INSTANCE]) {
  257. NL_SET_ERR_MSG_MOD(extack, "Missing INSTANCE attribute");
  258. return -EINVAL;
  259. }
  260. if (!tb[IFLA_BRIDGE_CFM_CC_RDI_RDI]) {
  261. NL_SET_ERR_MSG_MOD(extack, "Missing RDI attribute");
  262. return -EINVAL;
  263. }
  264. instance = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_RDI_INSTANCE]);
  265. rdi = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_RDI_RDI]);
  266. return br_cfm_cc_rdi_set(br, instance, rdi, extack);
  267. }
  268. static int br_cc_ccm_tx_parse(struct net_bridge *br, struct nlattr *attr,
  269. struct netlink_ext_ack *extack)
  270. {
  271. struct nlattr *tb[IFLA_BRIDGE_CFM_CC_CCM_TX_MAX + 1];
  272. struct br_cfm_cc_ccm_tx_info tx_info;
  273. u32 instance;
  274. int err;
  275. err = nla_parse_nested(tb, IFLA_BRIDGE_CFM_CC_CCM_TX_MAX, attr,
  276. br_cfm_cc_ccm_tx_policy, extack);
  277. if (err)
  278. return err;
  279. if (!tb[IFLA_BRIDGE_CFM_CC_CCM_TX_INSTANCE]) {
  280. NL_SET_ERR_MSG_MOD(extack, "Missing INSTANCE attribute");
  281. return -EINVAL;
  282. }
  283. if (!tb[IFLA_BRIDGE_CFM_CC_CCM_TX_DMAC]) {
  284. NL_SET_ERR_MSG_MOD(extack, "Missing DMAC attribute");
  285. return -EINVAL;
  286. }
  287. if (!tb[IFLA_BRIDGE_CFM_CC_CCM_TX_SEQ_NO_UPDATE]) {
  288. NL_SET_ERR_MSG_MOD(extack, "Missing SEQ_NO_UPDATE attribute");
  289. return -EINVAL;
  290. }
  291. if (!tb[IFLA_BRIDGE_CFM_CC_CCM_TX_PERIOD]) {
  292. NL_SET_ERR_MSG_MOD(extack, "Missing PERIOD attribute");
  293. return -EINVAL;
  294. }
  295. if (!tb[IFLA_BRIDGE_CFM_CC_CCM_TX_IF_TLV]) {
  296. NL_SET_ERR_MSG_MOD(extack, "Missing IF_TLV attribute");
  297. return -EINVAL;
  298. }
  299. if (!tb[IFLA_BRIDGE_CFM_CC_CCM_TX_IF_TLV_VALUE]) {
  300. NL_SET_ERR_MSG_MOD(extack, "Missing IF_TLV_VALUE attribute");
  301. return -EINVAL;
  302. }
  303. if (!tb[IFLA_BRIDGE_CFM_CC_CCM_TX_PORT_TLV]) {
  304. NL_SET_ERR_MSG_MOD(extack, "Missing PORT_TLV attribute");
  305. return -EINVAL;
  306. }
  307. if (!tb[IFLA_BRIDGE_CFM_CC_CCM_TX_PORT_TLV_VALUE]) {
  308. NL_SET_ERR_MSG_MOD(extack, "Missing PORT_TLV_VALUE attribute");
  309. return -EINVAL;
  310. }
  311. memset(&tx_info, 0, sizeof(tx_info));
  312. instance = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_RDI_INSTANCE]);
  313. nla_memcpy(&tx_info.dmac.addr,
  314. tb[IFLA_BRIDGE_CFM_CC_CCM_TX_DMAC],
  315. sizeof(tx_info.dmac.addr));
  316. tx_info.seq_no_update = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_CCM_TX_SEQ_NO_UPDATE]);
  317. tx_info.period = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_CCM_TX_PERIOD]);
  318. tx_info.if_tlv = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_CCM_TX_IF_TLV]);
  319. tx_info.if_tlv_value = nla_get_u8(tb[IFLA_BRIDGE_CFM_CC_CCM_TX_IF_TLV_VALUE]);
  320. tx_info.port_tlv = nla_get_u32(tb[IFLA_BRIDGE_CFM_CC_CCM_TX_PORT_TLV]);
  321. tx_info.port_tlv_value = nla_get_u8(tb[IFLA_BRIDGE_CFM_CC_CCM_TX_PORT_TLV_VALUE]);
  322. return br_cfm_cc_ccm_tx(br, instance, &tx_info, extack);
  323. }
  324. int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p,
  325. struct nlattr *attr, int cmd, struct netlink_ext_ack *extack)
  326. {
  327. struct nlattr *tb[IFLA_BRIDGE_CFM_MAX + 1];
  328. int err;
  329. /* When this function is called for a port then the br pointer is
  330. * invalid, therefor set the br to point correctly
  331. */
  332. if (p)
  333. br = p->br;
  334. err = nla_parse_nested(tb, IFLA_BRIDGE_CFM_MAX, attr,
  335. br_cfm_policy, extack);
  336. if (err)
  337. return err;
  338. if (tb[IFLA_BRIDGE_CFM_MEP_CREATE]) {
  339. err = br_mep_create_parse(br, tb[IFLA_BRIDGE_CFM_MEP_CREATE],
  340. extack);
  341. if (err)
  342. return err;
  343. }
  344. if (tb[IFLA_BRIDGE_CFM_MEP_DELETE]) {
  345. err = br_mep_delete_parse(br, tb[IFLA_BRIDGE_CFM_MEP_DELETE],
  346. extack);
  347. if (err)
  348. return err;
  349. }
  350. if (tb[IFLA_BRIDGE_CFM_MEP_CONFIG]) {
  351. err = br_mep_config_parse(br, tb[IFLA_BRIDGE_CFM_MEP_CONFIG],
  352. extack);
  353. if (err)
  354. return err;
  355. }
  356. if (tb[IFLA_BRIDGE_CFM_CC_CONFIG]) {
  357. err = br_cc_config_parse(br, tb[IFLA_BRIDGE_CFM_CC_CONFIG],
  358. extack);
  359. if (err)
  360. return err;
  361. }
  362. if (tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_ADD]) {
  363. err = br_cc_peer_mep_add_parse(br, tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_ADD],
  364. extack);
  365. if (err)
  366. return err;
  367. }
  368. if (tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_REMOVE]) {
  369. err = br_cc_peer_mep_remove_parse(br, tb[IFLA_BRIDGE_CFM_CC_PEER_MEP_REMOVE],
  370. extack);
  371. if (err)
  372. return err;
  373. }
  374. if (tb[IFLA_BRIDGE_CFM_CC_RDI]) {
  375. err = br_cc_rdi_parse(br, tb[IFLA_BRIDGE_CFM_CC_RDI],
  376. extack);
  377. if (err)
  378. return err;
  379. }
  380. if (tb[IFLA_BRIDGE_CFM_CC_CCM_TX]) {
  381. err = br_cc_ccm_tx_parse(br, tb[IFLA_BRIDGE_CFM_CC_CCM_TX],
  382. extack);
  383. if (err)
  384. return err;
  385. }
  386. return 0;
  387. }
  388. int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br)
  389. {
  390. struct br_cfm_peer_mep *peer_mep;
  391. struct br_cfm_mep *mep;
  392. struct nlattr *tb;
  393. hlist_for_each_entry_rcu(mep, &br->mep_list, head) {
  394. tb = nla_nest_start(skb, IFLA_BRIDGE_CFM_MEP_CREATE_INFO);
  395. if (!tb)
  396. goto nla_info_failure;
  397. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_MEP_CREATE_INSTANCE,
  398. mep->instance))
  399. goto nla_put_failure;
  400. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_MEP_CREATE_DOMAIN,
  401. mep->create.domain))
  402. goto nla_put_failure;
  403. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_MEP_CREATE_DIRECTION,
  404. mep->create.direction))
  405. goto nla_put_failure;
  406. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_MEP_CREATE_IFINDEX,
  407. mep->create.ifindex))
  408. goto nla_put_failure;
  409. nla_nest_end(skb, tb);
  410. tb = nla_nest_start(skb, IFLA_BRIDGE_CFM_MEP_CONFIG_INFO);
  411. if (!tb)
  412. goto nla_info_failure;
  413. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_MEP_CONFIG_INSTANCE,
  414. mep->instance))
  415. goto nla_put_failure;
  416. if (nla_put(skb, IFLA_BRIDGE_CFM_MEP_CONFIG_UNICAST_MAC,
  417. sizeof(mep->config.unicast_mac.addr),
  418. mep->config.unicast_mac.addr))
  419. goto nla_put_failure;
  420. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_MEP_CONFIG_MDLEVEL,
  421. mep->config.mdlevel))
  422. goto nla_put_failure;
  423. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_MEP_CONFIG_MEPID,
  424. mep->config.mepid))
  425. goto nla_put_failure;
  426. nla_nest_end(skb, tb);
  427. tb = nla_nest_start(skb, IFLA_BRIDGE_CFM_CC_CONFIG_INFO);
  428. if (!tb)
  429. goto nla_info_failure;
  430. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_CONFIG_INSTANCE,
  431. mep->instance))
  432. goto nla_put_failure;
  433. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_CONFIG_ENABLE,
  434. mep->cc_config.enable))
  435. goto nla_put_failure;
  436. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_CONFIG_EXP_INTERVAL,
  437. mep->cc_config.exp_interval))
  438. goto nla_put_failure;
  439. if (nla_put(skb, IFLA_BRIDGE_CFM_CC_CONFIG_EXP_MAID,
  440. sizeof(mep->cc_config.exp_maid.data),
  441. mep->cc_config.exp_maid.data))
  442. goto nla_put_failure;
  443. nla_nest_end(skb, tb);
  444. tb = nla_nest_start(skb, IFLA_BRIDGE_CFM_CC_RDI_INFO);
  445. if (!tb)
  446. goto nla_info_failure;
  447. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_RDI_INSTANCE,
  448. mep->instance))
  449. goto nla_put_failure;
  450. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_RDI_RDI,
  451. mep->rdi))
  452. goto nla_put_failure;
  453. nla_nest_end(skb, tb);
  454. tb = nla_nest_start(skb, IFLA_BRIDGE_CFM_CC_CCM_TX_INFO);
  455. if (!tb)
  456. goto nla_info_failure;
  457. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_CCM_TX_INSTANCE,
  458. mep->instance))
  459. goto nla_put_failure;
  460. if (nla_put(skb, IFLA_BRIDGE_CFM_CC_CCM_TX_DMAC,
  461. sizeof(mep->cc_ccm_tx_info.dmac),
  462. mep->cc_ccm_tx_info.dmac.addr))
  463. goto nla_put_failure;
  464. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_CCM_TX_SEQ_NO_UPDATE,
  465. mep->cc_ccm_tx_info.seq_no_update))
  466. goto nla_put_failure;
  467. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_CCM_TX_PERIOD,
  468. mep->cc_ccm_tx_info.period))
  469. goto nla_put_failure;
  470. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_CCM_TX_IF_TLV,
  471. mep->cc_ccm_tx_info.if_tlv))
  472. goto nla_put_failure;
  473. if (nla_put_u8(skb, IFLA_BRIDGE_CFM_CC_CCM_TX_IF_TLV_VALUE,
  474. mep->cc_ccm_tx_info.if_tlv_value))
  475. goto nla_put_failure;
  476. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_CCM_TX_PORT_TLV,
  477. mep->cc_ccm_tx_info.port_tlv))
  478. goto nla_put_failure;
  479. if (nla_put_u8(skb, IFLA_BRIDGE_CFM_CC_CCM_TX_PORT_TLV_VALUE,
  480. mep->cc_ccm_tx_info.port_tlv_value))
  481. goto nla_put_failure;
  482. nla_nest_end(skb, tb);
  483. hlist_for_each_entry_rcu(peer_mep, &mep->peer_mep_list, head) {
  484. tb = nla_nest_start(skb,
  485. IFLA_BRIDGE_CFM_CC_PEER_MEP_INFO);
  486. if (!tb)
  487. goto nla_info_failure;
  488. if (nla_put_u32(skb,
  489. IFLA_BRIDGE_CFM_CC_PEER_MEP_INSTANCE,
  490. mep->instance))
  491. goto nla_put_failure;
  492. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_PEER_MEPID,
  493. peer_mep->mepid))
  494. goto nla_put_failure;
  495. nla_nest_end(skb, tb);
  496. }
  497. }
  498. return 0;
  499. nla_put_failure:
  500. nla_nest_cancel(skb, tb);
  501. nla_info_failure:
  502. return -EMSGSIZE;
  503. }
  504. int br_cfm_status_fill_info(struct sk_buff *skb,
  505. struct net_bridge *br,
  506. bool getlink)
  507. {
  508. struct br_cfm_peer_mep *peer_mep;
  509. struct br_cfm_mep *mep;
  510. struct nlattr *tb;
  511. hlist_for_each_entry_rcu(mep, &br->mep_list, head) {
  512. tb = nla_nest_start(skb, IFLA_BRIDGE_CFM_MEP_STATUS_INFO);
  513. if (!tb)
  514. goto nla_info_failure;
  515. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_MEP_STATUS_INSTANCE,
  516. mep->instance))
  517. goto nla_put_failure;
  518. if (nla_put_u32(skb,
  519. IFLA_BRIDGE_CFM_MEP_STATUS_OPCODE_UNEXP_SEEN,
  520. mep->status.opcode_unexp_seen))
  521. goto nla_put_failure;
  522. if (nla_put_u32(skb,
  523. IFLA_BRIDGE_CFM_MEP_STATUS_VERSION_UNEXP_SEEN,
  524. mep->status.version_unexp_seen))
  525. goto nla_put_failure;
  526. if (nla_put_u32(skb,
  527. IFLA_BRIDGE_CFM_MEP_STATUS_RX_LEVEL_LOW_SEEN,
  528. mep->status.rx_level_low_seen))
  529. goto nla_put_failure;
  530. /* Only clear if this is a GETLINK */
  531. if (getlink) {
  532. /* Clear all 'seen' indications */
  533. mep->status.opcode_unexp_seen = false;
  534. mep->status.version_unexp_seen = false;
  535. mep->status.rx_level_low_seen = false;
  536. }
  537. nla_nest_end(skb, tb);
  538. hlist_for_each_entry_rcu(peer_mep, &mep->peer_mep_list, head) {
  539. tb = nla_nest_start(skb,
  540. IFLA_BRIDGE_CFM_CC_PEER_STATUS_INFO);
  541. if (!tb)
  542. goto nla_info_failure;
  543. if (nla_put_u32(skb,
  544. IFLA_BRIDGE_CFM_CC_PEER_STATUS_INSTANCE,
  545. mep->instance))
  546. goto nla_put_failure;
  547. if (nla_put_u32(skb,
  548. IFLA_BRIDGE_CFM_CC_PEER_STATUS_PEER_MEPID,
  549. peer_mep->mepid))
  550. goto nla_put_failure;
  551. if (nla_put_u32(skb,
  552. IFLA_BRIDGE_CFM_CC_PEER_STATUS_CCM_DEFECT,
  553. peer_mep->cc_status.ccm_defect))
  554. goto nla_put_failure;
  555. if (nla_put_u32(skb, IFLA_BRIDGE_CFM_CC_PEER_STATUS_RDI,
  556. peer_mep->cc_status.rdi))
  557. goto nla_put_failure;
  558. if (nla_put_u8(skb,
  559. IFLA_BRIDGE_CFM_CC_PEER_STATUS_PORT_TLV_VALUE,
  560. peer_mep->cc_status.port_tlv_value))
  561. goto nla_put_failure;
  562. if (nla_put_u8(skb,
  563. IFLA_BRIDGE_CFM_CC_PEER_STATUS_IF_TLV_VALUE,
  564. peer_mep->cc_status.if_tlv_value))
  565. goto nla_put_failure;
  566. if (nla_put_u32(skb,
  567. IFLA_BRIDGE_CFM_CC_PEER_STATUS_SEEN,
  568. peer_mep->cc_status.seen))
  569. goto nla_put_failure;
  570. if (nla_put_u32(skb,
  571. IFLA_BRIDGE_CFM_CC_PEER_STATUS_TLV_SEEN,
  572. peer_mep->cc_status.tlv_seen))
  573. goto nla_put_failure;
  574. if (nla_put_u32(skb,
  575. IFLA_BRIDGE_CFM_CC_PEER_STATUS_SEQ_UNEXP_SEEN,
  576. peer_mep->cc_status.seq_unexp_seen))
  577. goto nla_put_failure;
  578. if (getlink) { /* Only clear if this is a GETLINK */
  579. /* Clear all 'seen' indications */
  580. peer_mep->cc_status.seen = false;
  581. peer_mep->cc_status.tlv_seen = false;
  582. peer_mep->cc_status.seq_unexp_seen = false;
  583. }
  584. nla_nest_end(skb, tb);
  585. }
  586. }
  587. return 0;
  588. nla_put_failure:
  589. nla_nest_cancel(skb, tb);
  590. nla_info_failure:
  591. return -EMSGSIZE;
  592. }