@@ -1393,28 +1393,35 @@ static bool mptcp_pm_has_addr_attr_id(const struct nlattr *attr,
13931393
13941394int mptcp_pm_nl_add_addr_doit (struct sk_buff * skb , struct genl_info * info )
13951395{
1396- struct nlattr * attr = info -> attrs [MPTCP_PM_ENDPOINT_ADDR ];
13971396 struct pm_nl_pernet * pernet = genl_info_pm_nl (info );
13981397 struct mptcp_pm_addr_entry addr , * entry ;
1398+ struct nlattr * attr ;
13991399 int ret ;
14001400
1401+ if (GENL_REQ_ATTR_CHECK (info , MPTCP_PM_ENDPOINT_ADDR ))
1402+ return - EINVAL ;
1403+
1404+ attr = info -> attrs [MPTCP_PM_ENDPOINT_ADDR ];
14011405 ret = mptcp_pm_parse_entry (attr , info , true, & addr );
14021406 if (ret < 0 )
14031407 return ret ;
14041408
14051409 if (addr .addr .port && !address_use_port (& addr )) {
1406- GENL_SET_ERR_MSG (info , "flags must have signal and not subflow when using port" );
1410+ NL_SET_ERR_MSG_ATTR (info -> extack , attr ,
1411+ "flags must have signal and not subflow when using port" );
14071412 return - EINVAL ;
14081413 }
14091414
14101415 if (addr .flags & MPTCP_PM_ADDR_FLAG_SIGNAL &&
14111416 addr .flags & MPTCP_PM_ADDR_FLAG_FULLMESH ) {
1412- GENL_SET_ERR_MSG (info , "flags mustn't have both signal and fullmesh" );
1417+ NL_SET_ERR_MSG_ATTR (info -> extack , attr ,
1418+ "flags mustn't have both signal and fullmesh" );
14131419 return - EINVAL ;
14141420 }
14151421
14161422 if (addr .flags & MPTCP_PM_ADDR_FLAG_IMPLICIT ) {
1417- GENL_SET_ERR_MSG (info , "can't create IMPLICIT endpoint" );
1423+ NL_SET_ERR_MSG_ATTR (info -> extack , attr ,
1424+ "can't create IMPLICIT endpoint" );
14181425 return - EINVAL ;
14191426 }
14201427
@@ -1587,12 +1594,16 @@ static int mptcp_nl_remove_id_zero_address(struct net *net,
15871594
15881595int mptcp_pm_nl_del_addr_doit (struct sk_buff * skb , struct genl_info * info )
15891596{
1590- struct nlattr * attr = info -> attrs [MPTCP_PM_ENDPOINT_ADDR ];
15911597 struct pm_nl_pernet * pernet = genl_info_pm_nl (info );
15921598 struct mptcp_pm_addr_entry addr , * entry ;
15931599 unsigned int addr_max ;
1600+ struct nlattr * attr ;
15941601 int ret ;
15951602
1603+ if (GENL_REQ_ATTR_CHECK (info , MPTCP_PM_ENDPOINT_ADDR ))
1604+ return - EINVAL ;
1605+
1606+ attr = info -> attrs [MPTCP_PM_ENDPOINT_ADDR ];
15961607 ret = mptcp_pm_parse_entry (attr , info , false, & addr );
15971608 if (ret < 0 )
15981609 return ret ;
@@ -1608,7 +1619,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)
16081619 spin_lock_bh (& pernet -> lock );
16091620 entry = __lookup_addr_by_id (pernet , addr .addr .id );
16101621 if (!entry ) {
1611- GENL_SET_ERR_MSG (info , "address not found" );
1622+ NL_SET_ERR_MSG_ATTR (info -> extack , attr , "address not found" );
16121623 spin_unlock_bh (& pernet -> lock );
16131624 return - EINVAL ;
16141625 }
@@ -1764,13 +1775,17 @@ int mptcp_nl_fill_addr(struct sk_buff *skb,
17641775
17651776int mptcp_pm_nl_get_addr (struct sk_buff * skb , struct genl_info * info )
17661777{
1767- struct nlattr * attr = info -> attrs [MPTCP_PM_ENDPOINT_ADDR ];
17681778 struct pm_nl_pernet * pernet = genl_info_pm_nl (info );
17691779 struct mptcp_pm_addr_entry addr , * entry ;
17701780 struct sk_buff * msg ;
1781+ struct nlattr * attr ;
17711782 void * reply ;
17721783 int ret ;
17731784
1785+ if (GENL_REQ_ATTR_CHECK (info , MPTCP_PM_ENDPOINT_ADDR ))
1786+ return - EINVAL ;
1787+
1788+ attr = info -> attrs [MPTCP_PM_ENDPOINT_ADDR ];
17741789 ret = mptcp_pm_parse_entry (attr , info , false, & addr );
17751790 if (ret < 0 )
17761791 return ret ;
@@ -1790,7 +1805,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
17901805 rcu_read_lock ();
17911806 entry = __lookup_addr_by_id (pernet , addr .addr .id );
17921807 if (!entry ) {
1793- GENL_SET_ERR_MSG (info , "address not found" );
1808+ NL_SET_ERR_MSG_ATTR (info -> extack , attr , "address not found" );
17941809 ret = - EINVAL ;
17951810 goto unlock_fail ;
17961811 }
@@ -1875,7 +1890,9 @@ static int parse_limit(struct genl_info *info, int id, unsigned int *limit)
18751890
18761891 * limit = nla_get_u32 (attr );
18771892 if (* limit > MPTCP_PM_ADDR_MAX ) {
1878- GENL_SET_ERR_MSG (info , "limit greater than maximum" );
1893+ NL_SET_ERR_MSG_ATTR_FMT (info -> extack , attr ,
1894+ "limit greater than maximum (%u)" ,
1895+ MPTCP_PM_ADDR_MAX );
18791896 return - EINVAL ;
18801897 }
18811898 return 0 ;
@@ -1984,26 +2001,31 @@ static int mptcp_nl_set_flags(struct net *net,
19842001int mptcp_pm_nl_set_flags (struct sk_buff * skb , struct genl_info * info )
19852002{
19862003 struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, };
1987- struct nlattr * attr = info -> attrs [MPTCP_PM_ATTR_ADDR ];
19882004 u8 changed , mask = MPTCP_PM_ADDR_FLAG_BACKUP |
19892005 MPTCP_PM_ADDR_FLAG_FULLMESH ;
19902006 struct net * net = sock_net (skb -> sk );
19912007 struct mptcp_pm_addr_entry * entry ;
19922008 struct pm_nl_pernet * pernet ;
2009+ struct nlattr * attr ;
19932010 u8 lookup_by_id = 0 ;
19942011 u8 bkup = 0 ;
19952012 int ret ;
19962013
2014+ if (GENL_REQ_ATTR_CHECK (info , MPTCP_PM_ATTR_ADDR ))
2015+ return - EINVAL ;
2016+
19972017 pernet = pm_nl_get_pernet (net );
19982018
2019+ attr = info -> attrs [MPTCP_PM_ATTR_ADDR ];
19992020 ret = mptcp_pm_parse_entry (attr , info , false, & addr );
20002021 if (ret < 0 )
20012022 return ret ;
20022023
20032024 if (addr .addr .family == AF_UNSPEC ) {
20042025 lookup_by_id = 1 ;
20052026 if (!addr .addr .id ) {
2006- GENL_SET_ERR_MSG (info , "missing required inputs" );
2027+ NL_SET_ERR_MSG_ATTR (info -> extack , attr ,
2028+ "missing address ID" );
20072029 return - EOPNOTSUPP ;
20082030 }
20092031 }
@@ -2016,13 +2038,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info)
20162038 __lookup_addr (pernet , & addr .addr );
20172039 if (!entry ) {
20182040 spin_unlock_bh (& pernet -> lock );
2019- GENL_SET_ERR_MSG (info , "address not found" );
2041+ NL_SET_ERR_MSG_ATTR (info -> extack , attr , "address not found" );
20202042 return - EINVAL ;
20212043 }
20222044 if ((addr .flags & MPTCP_PM_ADDR_FLAG_FULLMESH ) &&
20232045 (entry -> flags & MPTCP_PM_ADDR_FLAG_SIGNAL )) {
20242046 spin_unlock_bh (& pernet -> lock );
2025- GENL_SET_ERR_MSG (info , "invalid addr flags" );
2047+ NL_SET_ERR_MSG_ATTR (info -> extack , attr , "invalid addr flags" );
20262048 return - EINVAL ;
20272049 }
20282050
0 commit comments