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

net: sctp: introduce uapi header for sctp

This patch introduces an UAPI header for the SCTP protocol,
so that we can facilitate the maintenance and development of
user land applications or libraries, in particular in terms
of header synchronization.

To not break compatibility, some fragments from lksctp-tools'
netinet/sctp.h have been carefully included, while taking care
that neither kernel nor user land breaks, so both compile fine
with this change (for lksctp-tools I tested with the old
netinet/sctp.h header and with a newly adapted one that includes
the uapi sctp header). lksctp-tools smoke test run through
successfully as well in both cases.

Suggested-by: Neil Horman <nhorman@tuxdriver.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Vlad Yasevich <vyasevich@gmail.com>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Daniel Borkmann and committed by
David S. Miller
1b866434 3d4a1316

+78 -16
+1 -1
fs/dlm/lowcomms.c
··· 52 52 #include <linux/mutex.h> 53 53 #include <linux/sctp.h> 54 54 #include <linux/slab.h> 55 + #include <linux/sctp.h> 55 56 #include <net/sctp/sctp.h> 56 - #include <net/sctp/user.h> 57 57 #include <net/ipv6.h> 58 58 59 59 #include "dlm_internal.h"
+2 -4
include/linux/sctp.h
··· 53 53 54 54 #include <linux/in.h> /* We need in_addr. */ 55 55 #include <linux/in6.h> /* We need in6_addr. */ 56 + #include <linux/skbuff.h> 56 57 58 + #include <uapi/linux/sctp.h> 57 59 58 60 /* Section 3.1. SCTP Common Header Format */ 59 61 typedef struct sctphdr { ··· 65 63 __le32 checksum; 66 64 } __packed sctp_sctphdr_t; 67 65 68 - #ifdef __KERNEL__ 69 - #include <linux/skbuff.h> 70 - 71 66 static inline struct sctphdr *sctp_hdr(const struct sk_buff *skb) 72 67 { 73 68 return (struct sctphdr *)skb_transport_header(skb); 74 69 } 75 - #endif 76 70 77 71 /* Section 3.2. Chunk Field Descriptions. */ 78 72 typedef struct sctp_chunkhdr {
-1
include/net/sctp/constants.h
··· 49 49 50 50 #include <linux/sctp.h> 51 51 #include <linux/ipv6.h> /* For ipv6hdr. */ 52 - #include <net/sctp/user.h> 53 52 #include <net/tcp_states.h> /* For TCP states used in sctp_sock_state_t */ 54 53 55 54 /* Value used for stream negotiation. */
+74 -10
include/net/sctp/user.h include/uapi/linux/sctp.h
··· 42 42 * Jon Grimm <jgrimm@us.ibm.com> 43 43 * Daisy Chang <daisyc@us.ibm.com> 44 44 * Ryan Layer <rmlayer@us.ibm.com> 45 - * Ardelle Fan <ardelle.fan@intel.com> 45 + * Ardelle Fan <ardelle.fan@intel.com> 46 46 * Sridhar Samudrala <sri@us.ibm.com> 47 + * Inaky Perez-Gonzalez <inaky.gonzalez@intel.com> 48 + * Vlad Yasevich <vladislav.yasevich@hp.com> 47 49 * 48 50 * Any bugs reported given to us we will try to fix... any fixes shared will 49 51 * be incorporated into the next SCTP release. 50 52 */ 51 53 52 - #ifndef __net_sctp_user_h__ 53 - #define __net_sctp_user_h__ 54 + #ifndef _UAPI_SCTP_H 55 + #define _UAPI_SCTP_H 54 56 55 57 #include <linux/types.h> 56 58 #include <linux/socket.h> ··· 167 165 SCTP_ADDR_OVER = 2, /* Override the primary destination. */ 168 166 SCTP_ABORT=4, /* Send an ABORT message to the peer. */ 169 167 SCTP_SACK_IMMEDIATELY = 8, /* SACK should be sent without delay */ 170 - SCTP_EOF=MSG_FIN, /* Initiate graceful shutdown process. */ 168 + SCTP_EOF=MSG_FIN, /* Initiate graceful shutdown process. */ 171 169 }; 172 170 171 + typedef union { 172 + __u8 raw; 173 + struct sctp_initmsg init; 174 + struct sctp_sndrcvinfo sndrcv; 175 + } sctp_cmsg_data_t; 173 176 174 177 /* These are cmsg_types. */ 175 178 typedef enum sctp_cmsg_type { 176 179 SCTP_INIT, /* 5.2.1 SCTP Initiation Structure */ 180 + #define SCTP_INIT SCTP_INIT 177 181 SCTP_SNDRCV, /* 5.2.2 SCTP Header Information Structure */ 182 + #define SCTP_SNDRCV SCTP_SNDRCV 178 183 } sctp_cmsg_t; 179 - 180 184 181 185 /* 182 186 * 5.3.1.1 SCTP_ASSOC_CHANGE ··· 353 345 354 346 enum { SCTP_PARTIAL_DELIVERY_ABORTED=0, }; 355 347 348 + /* 349 + * 5.3.1.8. SCTP_AUTHENTICATION_EVENT 350 + * 351 + * When a receiver is using authentication this message will provide 352 + * notifications regarding new keys being made active as well as errors. 353 + */ 356 354 struct sctp_authkey_event { 357 355 __u16 auth_type; 358 356 __u16 auth_flags; ··· 435 421 enum sctp_sn_type { 436 422 SCTP_SN_TYPE_BASE = (1<<15), 437 423 SCTP_ASSOC_CHANGE, 424 + #define SCTP_ASSOC_CHANGE SCTP_ASSOC_CHANGE 438 425 SCTP_PEER_ADDR_CHANGE, 426 + #define SCTP_PEER_ADDR_CHANGE SCTP_PEER_ADDR_CHANGE 439 427 SCTP_SEND_FAILED, 428 + #define SCTP_SEND_FAILED SCTP_SEND_FAILED 440 429 SCTP_REMOTE_ERROR, 430 + #define SCTP_REMOTE_ERROR SCTP_REMOTE_ERROR 441 431 SCTP_SHUTDOWN_EVENT, 432 + #define SCTP_SHUTDOWN_EVENT SCTP_SHUTDOWN_EVENT 442 433 SCTP_PARTIAL_DELIVERY_EVENT, 434 + #define SCTP_PARTIAL_DELIVERY_EVENT SCTP_PARTIAL_DELIVERY_EVENT 443 435 SCTP_ADAPTATION_INDICATION, 436 + #define SCTP_ADAPTATION_INDICATION SCTP_ADAPTATION_INDICATION 444 437 SCTP_AUTHENTICATION_EVENT, 445 438 #define SCTP_AUTHENTICATION_INDICATION SCTP_AUTHENTICATION_EVENT 446 439 SCTP_SENDER_DRY_EVENT, 440 + #define SCTP_SENDER_DRY_EVENT SCTP_SENDER_DRY_EVENT 447 441 }; 448 442 449 443 /* Notification error codes used to fill up the error fields in some ··· 476 454 * 477 455 * The protocol parameters used to initialize and bound retransmission 478 456 * timeout (RTO) are tunable. See [SCTP] for more information on how 479 - * these parameters are used in RTO calculation. 457 + * these parameters are used in RTO calculation. 480 458 */ 481 459 struct sctp_rtoinfo { 482 460 sctp_assoc_t srto_assoc_id; ··· 525 503 sctp_assoc_t ssp_assoc_id; 526 504 struct sockaddr_storage ssp_addr; 527 505 } __attribute__((packed, aligned(4))); 506 + 507 + /* For backward compatibility use, define the old name too */ 508 + #define sctp_setprim sctp_prim 528 509 529 510 /* 530 511 * 7.1.11 Set Adaptation Layer Indicator (SCTP_ADAPTATION_LAYER) ··· 589 564 * 590 565 * This option gets or sets the list of HMAC algorithms that the local 591 566 * endpoint requires the peer to use. 592 - */ 567 + */ 568 + #ifndef __KERNEL__ 569 + /* This here is only used by user space as is. It might not be a good idea 570 + * to export/reveal the whole structure with reserved fields etc. 571 + */ 572 + enum { 573 + SCTP_AUTH_HMAC_ID_SHA1 = 1, 574 + SCTP_AUTH_HMAC_ID_SHA256 = 3, 575 + }; 576 + #endif 577 + 593 578 struct sctp_hmacalgo { 594 579 __u32 shmac_num_idents; 595 580 __u16 shmac_idents[]; 596 581 }; 582 + 583 + /* Sadly, user and kernel space have different names for 584 + * this structure member, so this is to not break anything. 585 + */ 586 + #define shmac_number_of_idents shmac_num_idents 597 587 598 588 /* 599 589 * 7.1.20. Set a shared key (SCTP_AUTH_KEY) ··· 731 691 uint8_t gauth_chunks[]; 732 692 }; 733 693 694 + /* The broken spelling has been released already in lksctp-tools header, 695 + * so don't break anyone, now that it's fixed. 696 + */ 697 + #define guth_number_of_chunks gauth_number_of_chunks 698 + 699 + /* Association states. */ 700 + enum sctp_sstat_state { 701 + SCTP_EMPTY = 0, 702 + SCTP_CLOSED = 1, 703 + SCTP_COOKIE_WAIT = 2, 704 + SCTP_COOKIE_ECHOED = 3, 705 + SCTP_ESTABLISHED = 4, 706 + SCTP_SHUTDOWN_PENDING = 5, 707 + SCTP_SHUTDOWN_SENT = 6, 708 + SCTP_SHUTDOWN_RECEIVED = 7, 709 + SCTP_SHUTDOWN_ACK_SENT = 8, 710 + }; 711 + 734 712 /* 735 713 * 8.2.6. Get the Current Identifiers of Associations 736 714 * (SCTP_GET_ASSOC_ID_LIST) ··· 763 705 764 706 /* 765 707 * 8.3, 8.5 get all peer/local addresses in an association. 766 - * This parameter struct is used by SCTP_GET_PEER_ADDRS and 708 + * This parameter struct is used by SCTP_GET_PEER_ADDRS and 767 709 * SCTP_GET_LOCAL_ADDRS socket options used internally to implement 768 - * sctp_getpaddrs() and sctp_getladdrs() API. 710 + * sctp_getpaddrs() and sctp_getladdrs() API. 769 711 */ 770 712 struct sctp_getaddrs_old { 771 713 sctp_assoc_t assoc_id; 772 714 int addr_num; 715 + #ifdef __KERNEL__ 773 716 struct sockaddr __user *addrs; 717 + #else 718 + struct sockaddr *addrs; 719 + #endif 774 720 }; 721 + 775 722 struct sctp_getaddrs { 776 723 sctp_assoc_t assoc_id; /*input*/ 777 724 __u32 addr_num; /*output*/ ··· 842 779 __u16 spt_pathmaxrxt; 843 780 __u16 spt_pathpfthld; 844 781 }; 845 - #endif /* __net_sctp_user_h__ */ 782 + 783 + #endif /* _UAPI_SCTP_H */
+1
include/uapi/linux/Kbuild
··· 331 331 header-y += scc.h 332 332 header-y += sched.h 333 333 header-y += screen_info.h 334 + header-y += sctp.h 334 335 header-y += sdla.h 335 336 header-y += seccomp.h 336 337 header-y += securebits.h