Message ID | bdbd57b89b92716d17fecce1f658c60cca261bee.1602150362.git.lucien.xin@gmail.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | sctp: Implement RFC6951: UDP Encapsulation of SCTP | expand |
Hi Xin, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on net-next/master] url: https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd config: i386-randconfig-s002-20201008 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.2-218-gc0e96d6d-dirty # https://github.com/0day-ci/linux/commit/5f37023ae66b1c3df726e16ec30b9443394e1ed3 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211 git checkout 5f37023ae66b1c3df726e16ec30b9443394e1ed3 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> echo echo "sparse warnings: (new ones prefixed by >>)" echo net/sctp/socket.c: note: in included file (through include/net/sctp/sctp.h): include/net/sctp/structs.h:333:41: sparse: sparse: array of flexible structures >> net/sctp/socket.c:4439:31: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __be16 [usertype] encap_port @@ got unsigned short [usertype] sue_port @@ >> net/sctp/socket.c:4439:31: sparse: expected restricted __be16 [usertype] encap_port >> net/sctp/socket.c:4439:31: sparse: got unsigned short [usertype] sue_port net/sctp/socket.c:4458:39: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __be16 [usertype] encap_port @@ got unsigned short [usertype] sue_port @@ net/sctp/socket.c:4458:39: sparse: expected restricted __be16 [usertype] encap_port net/sctp/socket.c:4458:39: sparse: got unsigned short [usertype] sue_port net/sctp/socket.c:4463:33: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __be16 [usertype] encap_port @@ got unsigned short [usertype] sue_port @@ net/sctp/socket.c:4463:33: sparse: expected restricted __be16 [usertype] encap_port net/sctp/socket.c:4463:33: sparse: got unsigned short [usertype] sue_port >> net/sctp/socket.c:7869:32: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned short [addressable] [usertype] sue_port @@ got restricted __be16 [usertype] encap_port @@ >> net/sctp/socket.c:7869:32: sparse: expected unsigned short [addressable] [usertype] sue_port >> net/sctp/socket.c:7869:32: sparse: got restricted __be16 [usertype] encap_port net/sctp/socket.c:7885:32: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned short [addressable] [usertype] sue_port @@ got restricted __be16 [usertype] encap_port @@ net/sctp/socket.c:7885:32: sparse: expected unsigned short [addressable] [usertype] sue_port net/sctp/socket.c:7885:32: sparse: got restricted __be16 [usertype] encap_port net/sctp/socket.c:7889:24: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned short [addressable] [usertype] sue_port @@ got restricted __be16 [usertype] encap_port @@ net/sctp/socket.c:7889:24: sparse: expected unsigned short [addressable] [usertype] sue_port net/sctp/socket.c:7889:24: sparse: got restricted __be16 [usertype] encap_port net/sctp/socket.c:8320:23: sparse: sparse: context imbalance in 'sctp_get_port_local' - unexpected unlock vim +4439 net/sctp/socket.c 4419 4420 static int sctp_setsockopt_encap_port(struct sock *sk, 4421 struct sctp_udpencaps *encap, 4422 unsigned int optlen) 4423 { 4424 struct sctp_association *asoc; 4425 struct sctp_transport *t; 4426 4427 if (optlen != sizeof(*encap)) 4428 return -EINVAL; 4429 4430 /* If an address other than INADDR_ANY is specified, and 4431 * no transport is found, then the request is invalid. 4432 */ 4433 if (!sctp_is_any(sk, (union sctp_addr *)&encap->sue_address)) { 4434 t = sctp_addr_id2transport(sk, &encap->sue_address, 4435 encap->sue_assoc_id); 4436 if (!t) 4437 return -EINVAL; 4438 > 4439 t->encap_port = encap->sue_port; 4440 return 0; 4441 } 4442 4443 /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the 4444 * socket is a one to many style socket, and an association 4445 * was not found, then the id was invalid. 4446 */ 4447 asoc = sctp_id2assoc(sk, encap->sue_assoc_id); 4448 if (!asoc && encap->sue_assoc_id != SCTP_FUTURE_ASSOC && 4449 sctp_style(sk, UDP)) 4450 return -EINVAL; 4451 4452 /* If changes are for association, also apply encap to each 4453 * transport. 4454 */ 4455 if (asoc) { 4456 list_for_each_entry(t, &asoc->peer.transport_addr_list, 4457 transports) 4458 t->encap_port = encap->sue_port; 4459 4460 return 0; 4461 } 4462 4463 sctp_sk(sk)->encap_port = encap->sue_port; 4464 return 0; 4465 } 4466 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h index 28ad40d..cb78e7a 100644 --- a/include/uapi/linux/sctp.h +++ b/include/uapi/linux/sctp.h @@ -140,6 +140,7 @@ typedef __s32 sctp_assoc_t; #define SCTP_ECN_SUPPORTED 130 #define SCTP_EXPOSE_POTENTIALLY_FAILED_STATE 131 #define SCTP_EXPOSE_PF_STATE SCTP_EXPOSE_POTENTIALLY_FAILED_STATE +#define SCTP_REMOTE_UDP_ENCAPS_PORT 132 /* PR-SCTP policies */ #define SCTP_PR_SCTP_NONE 0x0000 @@ -1197,6 +1198,12 @@ struct sctp_event { uint8_t se_on; }; +struct sctp_udpencaps { + sctp_assoc_t sue_assoc_id; + struct sockaddr_storage sue_address; + uint16_t sue_port; +}; + /* SCTP Stream schedulers */ enum sctp_sched_type { SCTP_SS_FCFS, diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 09b94cd..c9e86f5 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -4417,6 +4417,53 @@ static int sctp_setsockopt_pf_expose(struct sock *sk, return retval; } +static int sctp_setsockopt_encap_port(struct sock *sk, + struct sctp_udpencaps *encap, + unsigned int optlen) +{ + struct sctp_association *asoc; + struct sctp_transport *t; + + if (optlen != sizeof(*encap)) + return -EINVAL; + + /* If an address other than INADDR_ANY is specified, and + * no transport is found, then the request is invalid. + */ + if (!sctp_is_any(sk, (union sctp_addr *)&encap->sue_address)) { + t = sctp_addr_id2transport(sk, &encap->sue_address, + encap->sue_assoc_id); + if (!t) + return -EINVAL; + + t->encap_port = encap->sue_port; + return 0; + } + + /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the + * socket is a one to many style socket, and an association + * was not found, then the id was invalid. + */ + asoc = sctp_id2assoc(sk, encap->sue_assoc_id); + if (!asoc && encap->sue_assoc_id != SCTP_FUTURE_ASSOC && + sctp_style(sk, UDP)) + return -EINVAL; + + /* If changes are for association, also apply encap to each + * transport. + */ + if (asoc) { + list_for_each_entry(t, &asoc->peer.transport_addr_list, + transports) + t->encap_port = encap->sue_port; + + return 0; + } + + sctp_sk(sk)->encap_port = encap->sue_port; + return 0; +} + /* API 6.2 setsockopt(), getsockopt() * * Applications use setsockopt() and getsockopt() to set or retrieve @@ -4636,6 +4683,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname, case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE: retval = sctp_setsockopt_pf_expose(sk, kopt, optlen); break; + case SCTP_REMOTE_UDP_ENCAPS_PORT: + retval = sctp_setsockopt_encap_port(sk, kopt, optlen); + break; default: retval = -ENOPROTOOPT; break; @@ -7791,6 +7841,63 @@ static int sctp_getsockopt_pf_expose(struct sock *sk, int len, return retval; } +static int sctp_getsockopt_encap_port(struct sock *sk, int len, + char __user *optval, int __user *optlen) +{ + struct sctp_association *asoc; + struct sctp_udpencaps encap; + struct sctp_transport *t; + + if (len < sizeof(encap)) + return -EINVAL; + + len = sizeof(encap); + if (copy_from_user(&encap, optval, len)) + return -EFAULT; + + /* If an address other than INADDR_ANY is specified, and + * no transport is found, then the request is invalid. + */ + if (!sctp_is_any(sk, (union sctp_addr *)&encap.sue_address)) { + t = sctp_addr_id2transport(sk, &encap.sue_address, + encap.sue_assoc_id); + if (!t) { + pr_debug("%s: failed no transport\n", __func__); + return -EINVAL; + } + + encap.sue_port = t->encap_port; + goto out; + } + + /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the + * socket is a one to many style socket, and an association + * was not found, then the id was invalid. + */ + asoc = sctp_id2assoc(sk, encap.sue_assoc_id); + if (!asoc && encap.sue_assoc_id != SCTP_FUTURE_ASSOC && + sctp_style(sk, UDP)) { + pr_debug("%s: failed no association\n", __func__); + return -EINVAL; + } + + if (asoc) { + encap.sue_port = asoc->encap_port; + goto out; + } + + encap.sue_port = sctp_sk(sk)->encap_port; + +out: + if (copy_to_user(optval, &encap, len)) + return -EFAULT; + + if (put_user(len, optlen)) + return -EFAULT; + + return 0; +} + static int sctp_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen) { @@ -8011,6 +8118,9 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname, case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE: retval = sctp_getsockopt_pf_expose(sk, len, optval, optlen); break; + case SCTP_REMOTE_UDP_ENCAPS_PORT: + retval = sctp_getsockopt_encap_port(sk, len, optval, optlen); + break; default: retval = -ENOPROTOOPT; break;
This patch is to implement: rfc6951#section-6.1: Get or Set the Remote UDP Encapsulation Port Number with the param of the struct: struct sctp_udpencaps { sctp_assoc_t sue_assoc_id; struct sockaddr_storage sue_address; uint16_t sue_port; }; the encap_port of sock, assoc or transport can be changed by users, which also means it allows the different transports of the same asoc to have different encap_port value. Signed-off-by: Xin Long <lucien.xin@gmail.com> --- include/uapi/linux/sctp.h | 7 +++ net/sctp/socket.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+)