- Restructure so bindx functions are not done inline to socket option

but are a seperate call that can be re-used if needed.
- 64 bit issues
  o re-arrange cookie so it is better 64 bit aligned
  o For wire level things we need the packed attribute.
This commit is contained in:
Randall Stewart 2007-06-12 11:21:00 +00:00
parent bebfe2adf7
commit 35918f8571
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=170606
10 changed files with 289 additions and 233 deletions

View File

@ -47,25 +47,27 @@ struct sctphdr {
uint32_t v_tag; /* verification tag of packet */
uint32_t checksum; /* Adler32 C-Sum */
/* chunks follow... */
};
}
__attribute__((packed));
/*
* SCTP Chunks
*/
struct sctp_chunkhdr {
uint8_t chunk_type; /* chunk type */
uint8_t chunk_flags; /* chunk flags */
uint16_t chunk_length; /* chunk length */
/* optional params follow */
};
struct sctp_chunkhdr {
uint8_t chunk_type; /* chunk type */
uint8_t chunk_flags; /* chunk flags */
uint16_t chunk_length; /* chunk length */
/* optional params follow */
} __attribute__((packed));
/*
* SCTP chunk parameters
*/
struct sctp_paramhdr {
uint16_t param_type; /* parameter type */
uint16_t param_length; /* parameter length */
};
struct sctp_paramhdr {
uint16_t param_type; /* parameter type */
uint16_t param_length; /* parameter length */
} __attribute__((packed));
/*
* user socket options: socket API defined
@ -290,42 +292,49 @@ struct sctp_paramhdr {
/*
* error cause parameters (user visisble)
*/
struct sctp_error_cause {
uint16_t code;
uint16_t length;
/* optional cause-specific info may follow */
};
struct sctp_error_cause {
uint16_t code;
uint16_t length;
/* optional cause-specific info may follow */
} __attribute__((packed));
struct sctp_error_invalid_stream {
struct sctp_error_cause cause; /* code=SCTP_ERROR_INVALID_STREAM */
uint16_t stream_id; /* stream id of the DATA in error */
uint16_t reserved;
};
struct sctp_error_invalid_stream {
struct sctp_error_cause cause; /* code=SCTP_ERROR_INVALID_STRE
* AM */
uint16_t stream_id; /* stream id of the DATA in error */
uint16_t reserved;
} __attribute__((packed));
struct sctp_error_missing_param {
struct sctp_error_cause cause; /* code=SCTP_ERROR_MISSING_PARAM */
uint32_t num_missing_params; /* number of missing parameters */
/* uint16_t param_type's follow */
};
struct sctp_error_missing_param {
struct sctp_error_cause cause; /* code=SCTP_ERROR_MISSING_PARA
* M */
uint32_t num_missing_params; /* number of missing
* parameters */
/* uint16_t param_type's follow */
} __attribute__((packed));
struct sctp_error_stale_cookie {
struct sctp_error_cause cause; /* code=SCTP_ERROR_STALE_COOKIE */
uint32_t stale_time; /* time in usec of staleness */
};
struct sctp_error_stale_cookie {
struct sctp_error_cause cause; /* code=SCTP_ERROR_STALE_COOKIE
* */
uint32_t stale_time; /* time in usec of staleness */
} __attribute__((packed));
struct sctp_error_out_of_resource {
struct sctp_error_cause cause; /* code=SCTP_ERROR_OUT_OF_RESOURCES */
};
struct sctp_error_out_of_resource {
struct sctp_error_cause cause; /* code=SCTP_ERROR_OUT_OF_RESOU
* RCES */
} __attribute__((packed));
struct sctp_error_unresolv_addr {
struct sctp_error_cause cause; /* code=SCTP_ERROR_UNRESOLVABLE_ADDR */
struct sctp_error_unresolv_addr {
struct sctp_error_cause cause; /* code=SCTP_ERROR_UNRESOLVABLE
* _ADDR */
};
} __attribute__((packed));
struct sctp_error_unrecognized_chunk {
struct sctp_error_cause cause; /* code=SCTP_ERROR_UNRECOG_CHUNK */
struct sctp_chunkhdr ch;/* header from chunk in error */
};
struct sctp_error_unrecognized_chunk {
struct sctp_error_cause cause; /* code=SCTP_ERROR_UNRECOG_CHUN
* K */
struct sctp_chunkhdr ch; /* header from chunk in error */
} __attribute__((packed));
#define HAVE_SCTP 1
#define HAVE_KERNEL_SCTP 1

View File

@ -683,7 +683,7 @@ __FBSDID("$FreeBSD$");
#define SCTP_SCALE_OF_RWND_TO_UPD 4
#define SCTP_MINIMAL_RWND (4096) /* minimal rwnd */
#define SCTP_ADDRMAX 20
#define SCTP_ADDRMAX 24
/* SCTP DEBUG Switch parameters */
#define SCTP_DEBUG_TIMER1 0x00000001

View File

@ -41,13 +41,14 @@ __FBSDID("$FreeBSD$");
#include <netinet/sctp.h>
#include <netinet/sctp_constants.h>
/*
* Parameter structures
*/
struct sctp_ipv4addr_param {
struct sctp_paramhdr ph;/* type=SCTP_IPV4_PARAM_TYPE, len=8 */
uint32_t addr; /* IPV4 address */
};
} SCTP_PACKED;
#define SCTP_V6_ADDR_BYTES 16
@ -55,7 +56,7 @@ struct sctp_ipv4addr_param {
struct sctp_ipv6addr_param {
struct sctp_paramhdr ph;/* type=SCTP_IPV6_PARAM_TYPE, len=20 */
uint8_t addr[SCTP_V6_ADDR_BYTES]; /* IPV6 address */
};
} SCTP_PACKED;
/* Cookie Preservative */
struct sctp_cookie_perserve_param {
@ -68,7 +69,7 @@ struct sctp_cookie_perserve_param {
struct sctp_host_name_param {
struct sctp_paramhdr ph;/* type=SCTP_HOSTNAME_ADDRESS */
char name[SCTP_ARRAY_MIN_LEN]; /* host name */
};
} SCTP_PACKED;
/*
* This is the maximum padded size of a s-a-p
@ -80,12 +81,12 @@ struct sctp_supported_addr_param {
struct sctp_paramhdr ph;/* type=SCTP_SUPPORTED_ADDRTYPE */
uint16_t addr_type[SCTP_ARRAY_MIN_LEN]; /* array of supported address
* types */
};
} SCTP_PACKED;
/* ECN parameter */
struct sctp_ecn_supported_param {
struct sctp_paramhdr ph;/* type=SCTP_ECN_CAPABLE */
};
} SCTP_PACKED;
/* heartbeat info parameter */
@ -99,44 +100,44 @@ struct sctp_heartbeat_info_param {
uint8_t addr_family;
uint8_t addr_len;
char address[SCTP_ADDRMAX];
};
} SCTP_PACKED;
/* draft-ietf-tsvwg-prsctp */
/* PR-SCTP supported parameter */
struct sctp_prsctp_supported_param {
struct sctp_paramhdr ph;
};
} SCTP_PACKED;
/* draft-ietf-tsvwg-addip-sctp */
struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */
struct sctp_paramhdr ph;/* a SCTP parameter header */
uint32_t correlation_id;/* correlation id for this param */
};
} SCTP_PACKED;
struct sctp_asconf_addr_param { /* an ASCONF address parameter */
struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
struct sctp_ipv6addr_param addrp; /* max storage size */
};
} SCTP_PACKED;
struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */
struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
struct sctp_ipv4addr_param addrp; /* max storage size */
};
} SCTP_PACKED;
#define SCTP_MAX_SUPPORTED_EXT 256
struct sctp_supported_chunk_types_param {
struct sctp_paramhdr ph;/* type = 0x8008 len = x */
uint8_t chunk_types[0];
};
} SCTP_PACKED;
/* ECN Nonce: draft-ladha-sctp-ecn-nonce */
struct sctp_ecn_nonce_supported_param {
struct sctp_paramhdr ph;/* type = 0x8001 len = 4 */
};
} SCTP_PACKED;
/*
@ -148,12 +149,12 @@ struct sctp_data {
uint16_t stream_sequence;
uint32_t protocol_id;
/* user data follows */
};
} SCTP_PACKED;
struct sctp_data_chunk {
struct sctp_chunkhdr ch;
struct sctp_data dp;
};
} SCTP_PACKED;
/*
* Structures for the control chunks
@ -167,38 +168,43 @@ struct sctp_init {
uint16_t num_inbound_streams; /* MIS */
uint32_t initial_tsn; /* I-TSN */
/* optional param's follow */
};
} SCTP_PACKED;
#define SCTP_IDENTIFICATION_SIZE 16
#define SCTP_ADDRESS_SIZE 4
#define SCTP_RESERVE_SPACE 6
/* state cookie header */
struct sctp_state_cookie { /* this is our definition... */
uint8_t identification[SCTP_IDENTIFICATION_SIZE]; /* id of who we are */
struct timeval time_entered; /* the time I built cookie */
uint32_t cookie_life; /* life I will award this cookie */
uint32_t tie_tag_my_vtag; /* my tag in old association */
uint32_t tie_tag_peer_vtag; /* peers tag in old association */
uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */
uint32_t my_vtag; /* my tag in INIT-ACK (for quick ref) */
struct timeval time_entered; /* the time I built cookie */
uint32_t address[SCTP_ADDRESS_SIZE]; /* 4 ints/128 bits */
uint32_t addr_type; /* address type */
uint32_t laddress[SCTP_ADDRESS_SIZE]; /* my local from address */
uint32_t laddr_type; /* my local from address type */
uint32_t scope_id; /* v6 scope id for link-locals */
uint16_t peerport; /* port address of the peer in the INIT */
uint16_t myport; /* my port address used in the INIT */
uint8_t ipv4_addr_legal;/* Are V4 addr legal? */
uint8_t ipv6_addr_legal;/* Are V6 addr legal? */
uint8_t local_scope; /* IPv6 local scope flag */
uint8_t site_scope; /* IPv6 site scope flag */
uint8_t ipv4_scope; /* IPv4 private addr scope */
uint8_t loopback_scope; /* loopback scope information */
uint16_t reserved;
uint8_t reserved[SCTP_RESERVE_SPACE]; /* Align to 64 bits */
/*
* at the end is tacked on the INIT chunk and the INIT-ACK chunk
* (minus the cookie).
*/
};
} SCTP_PACKED;
struct sctp_inv_mandatory_param {
uint16_t cause;
@ -210,30 +216,30 @@ struct sctp_inv_mandatory_param {
* this error.
*/
uint16_t resv;
};
} SCTP_PACKED;
struct sctp_unresolv_addr {
uint16_t cause;
uint16_t length;
uint16_t addr_type;
uint16_t reserved; /* Only one invalid addr type */
};
} SCTP_PACKED;
/* state cookie parameter */
struct sctp_state_cookie_param {
struct sctp_paramhdr ph;
struct sctp_state_cookie cookie;
};
} SCTP_PACKED;
struct sctp_init_chunk {
struct sctp_chunkhdr ch;
struct sctp_init init;
};
} SCTP_PACKED;
struct sctp_init_msg {
struct sctphdr sh;
struct sctp_init_chunk msg;
};
} SCTP_PACKED;
/* ... used for both INIT and INIT ACK */
#define sctp_init_ack sctp_init
@ -245,7 +251,7 @@ struct sctp_init_msg {
struct sctp_gap_ack_block {
uint16_t start; /* Gap Ack block start */
uint16_t end; /* Gap Ack block end */
};
} SCTP_PACKED;
struct sctp_sack {
uint32_t cum_tsn_ack; /* cumulative TSN Ack */
@ -254,23 +260,23 @@ struct sctp_sack {
uint16_t num_dup_tsns; /* number of duplicate TSNs */
/* struct sctp_gap_ack_block's follow */
/* uint32_t duplicate_tsn's follow */
};
} SCTP_PACKED;
struct sctp_sack_chunk {
struct sctp_chunkhdr ch;
struct sctp_sack sack;
};
} SCTP_PACKED;
/* Heartbeat Request (HEARTBEAT) */
struct sctp_heartbeat {
struct sctp_heartbeat_info_param hb_info;
};
} SCTP_PACKED;
struct sctp_heartbeat_chunk {
struct sctp_chunkhdr ch;
struct sctp_heartbeat heartbeat;
};
} SCTP_PACKED;
/* ... used for Heartbeat Ack (HEARTBEAT ACK) */
#define sctp_heartbeat_ack sctp_heartbeat
@ -281,83 +287,83 @@ struct sctp_heartbeat_chunk {
struct sctp_abort_chunk {
struct sctp_chunkhdr ch;
/* optional error cause may follow */
};
} SCTP_PACKED;
struct sctp_abort_msg {
struct sctphdr sh;
struct sctp_abort_chunk msg;
};
} SCTP_PACKED;
/* Shutdown Association (SHUTDOWN) */
struct sctp_shutdown_chunk {
struct sctp_chunkhdr ch;
uint32_t cumulative_tsn_ack;
};
} SCTP_PACKED;
/* Shutdown Acknowledgment (SHUTDOWN ACK) */
struct sctp_shutdown_ack_chunk {
struct sctp_chunkhdr ch;
};
} SCTP_PACKED;
/* Operation Error (ERROR) */
struct sctp_error_chunk {
struct sctp_chunkhdr ch;
/* optional error causes follow */
};
} SCTP_PACKED;
/* Cookie Echo (COOKIE ECHO) */
struct sctp_cookie_echo_chunk {
struct sctp_chunkhdr ch;
struct sctp_state_cookie cookie;
};
} SCTP_PACKED;
/* Cookie Acknowledgment (COOKIE ACK) */
struct sctp_cookie_ack_chunk {
struct sctp_chunkhdr ch;
};
} SCTP_PACKED;
/* Explicit Congestion Notification Echo (ECNE) */
struct sctp_ecne_chunk {
struct sctp_chunkhdr ch;
uint32_t tsn;
};
} SCTP_PACKED;
/* Congestion Window Reduced (CWR) */
struct sctp_cwr_chunk {
struct sctp_chunkhdr ch;
uint32_t tsn;
};
} SCTP_PACKED;
/* Shutdown Complete (SHUTDOWN COMPLETE) */
struct sctp_shutdown_complete_chunk {
struct sctp_chunkhdr ch;
};
} SCTP_PACKED;
/* Oper error holding a stale cookie */
struct sctp_stale_cookie_msg {
struct sctp_paramhdr ph;/* really an error cause */
uint32_t time_usec;
};
} SCTP_PACKED;
struct sctp_adaptation_layer_indication {
struct sctp_paramhdr ph;
uint32_t indication;
};
} SCTP_PACKED;
struct sctp_cookie_while_shutting_down {
struct sctphdr sh;
struct sctp_chunkhdr ch;
struct sctp_paramhdr ph;/* really an error cause */
};
} SCTP_PACKED;
struct sctp_shutdown_complete_msg {
struct sctphdr sh;
struct sctp_shutdown_complete_chunk shut_cmp;
};
} SCTP_PACKED;
/*
* draft-ietf-tsvwg-addip-sctp
@ -368,14 +374,14 @@ struct sctp_asconf_chunk {
uint32_t serial_number;
/* lookup address parameter (mandatory) */
/* asconf parameters follow */
};
} SCTP_PACKED;
/* Address/Stream Configuration Acknowledge (ASCONF ACK) */
struct sctp_asconf_ack_chunk {
struct sctp_chunkhdr ch;
uint32_t serial_number;
/* asconf parameters follow */
};
} SCTP_PACKED;
/* draft-ietf-tsvwg-prsctp */
/* Forward Cumulative TSN (FORWARD TSN) */
@ -383,17 +389,17 @@ struct sctp_forward_tsn_chunk {
struct sctp_chunkhdr ch;
uint32_t new_cumulative_tsn;
/* stream/sequence pairs (sctp_strseq) follow */
};
} SCTP_PACKED;
struct sctp_strseq {
uint16_t stream;
uint16_t sequence;
};
} SCTP_PACKED;
struct sctp_forward_tsn_msg {
struct sctphdr sh;
struct sctp_forward_tsn_chunk msg;
};
} SCTP_PACKED;
/* should be a multiple of 4 - 1 aka 3/7/11 etc. */
@ -403,7 +409,7 @@ struct sctp_chunk_desc {
uint8_t chunk_type;
uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY];
uint32_t tsn_ifany;
};
} SCTP_PACKED;
struct sctp_pktdrop_chunk {
@ -413,7 +419,7 @@ struct sctp_pktdrop_chunk {
uint16_t trunc_len;
uint16_t reserved;
uint8_t data[0];
};
} SCTP_PACKED;
/**********STREAM RESET STUFF ******************/
@ -423,25 +429,25 @@ struct sctp_stream_reset_out_request {
uint32_t response_seq; /* if a response, the resp seq no */
uint32_t send_reset_at_tsn; /* last TSN I assigned outbound */
uint16_t list_of_streams[0]; /* if not all list of streams */
};
} SCTP_PACKED;
struct sctp_stream_reset_in_request {
struct sctp_paramhdr ph;
uint32_t request_seq;
uint16_t list_of_streams[0]; /* if not all list of streams */
};
} SCTP_PACKED;
struct sctp_stream_reset_tsn_request {
struct sctp_paramhdr ph;
uint32_t request_seq;
};
} SCTP_PACKED;
struct sctp_stream_reset_response {
struct sctp_paramhdr ph;
uint32_t response_seq; /* if a response, the resp seq no */
uint32_t result;
};
} SCTP_PACKED;
struct sctp_stream_reset_response_tsn {
struct sctp_paramhdr ph;
@ -449,7 +455,7 @@ struct sctp_stream_reset_response_tsn {
uint32_t result;
uint32_t senders_next_tsn;
uint32_t receivers_next_tsn;
};
} SCTP_PACKED;
@ -468,28 +474,28 @@ struct sctp_stream_reset_response_tsn {
struct sctp_stream_reset_out_req {
struct sctp_chunkhdr ch;
struct sctp_stream_reset_out_request sr_req;
};
} SCTP_PACKED;
struct sctp_stream_reset_in_req {
struct sctp_chunkhdr ch;
struct sctp_stream_reset_in_request sr_req;
};
} SCTP_PACKED;
struct sctp_stream_reset_tsn_req {
struct sctp_chunkhdr ch;
struct sctp_stream_reset_tsn_request sr_req;
};
} SCTP_PACKED;
struct sctp_stream_reset_resp {
struct sctp_chunkhdr ch;
struct sctp_stream_reset_response sr_resp;
};
} SCTP_PACKED;
/* respone only valid with a TSN request */
struct sctp_stream_reset_resp_tsn {
struct sctp_chunkhdr ch;
struct sctp_stream_reset_response_tsn sr_resp;
};
} SCTP_PACKED;
/****************************************************/
@ -502,30 +508,30 @@ struct sctp_stream_reset_resp_tsn {
struct sctp_auth_random {
struct sctp_paramhdr ph;/* type = 0x8002 */
uint8_t random_data[0];
};
} SCTP_PACKED;
struct sctp_auth_chunk_list {
struct sctp_paramhdr ph;/* type = 0x8003 */
uint8_t chunk_types[0];
};
} SCTP_PACKED;
struct sctp_auth_hmac_algo {
struct sctp_paramhdr ph;/* type = 0x8004 */
uint16_t hmac_ids[0];
};
} SCTP_PACKED;
struct sctp_auth_chunk {
struct sctp_chunkhdr ch;
uint16_t shared_key_id;
uint16_t hmac_id;
uint8_t hmac[0];
};
} SCTP_PACKED;
struct sctp_auth_invalid_hmac {
struct sctp_paramhdr ph;
uint16_t hmac_id;
uint16_t padding;
};
} SCTP_PACKED;
/*
* we pre-reserve enough room for a ECNE or CWR AND a SACK with no missing

View File

@ -3884,6 +3884,11 @@ __attribute__((noinline))
cum_ack = ntohl(sack->sack.cum_tsn_ack);
num_seg = ntohs(sack->sack.num_gap_ack_blks);
a_rwnd = (uint32_t) ntohl(sack->sack.a_rwnd);
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_SACK process cum_ack:%x num_seg:%d a_rwnd:%d\n",
cum_ack,
num_seg,
a_rwnd
);
stcb->asoc.seen_a_sack_this_pkt = 1;
if ((stcb->asoc.pr_sctp_cnt == 0) &&
(num_seg == 0) &&

View File

@ -239,6 +239,9 @@ typedef struct callout sctp_os_timer_t;
#define sctp_get_tick_count() (ticks)
/* The packed define for 64 bit platforms */
#define SCTP_PACKED __attribute__((packed))
/*
* Functions
*/

View File

@ -3120,7 +3120,7 @@ sctp_add_cookie(struct sctp_inpcb *inp, struct mbuf *init, int init_offset,
ph->param_type = htons(SCTP_STATE_COOKIE);
ph->param_length = 0; /* fill in at the end */
/* Fill in the stc cookie data */
*stc = *stc_in;
memcpy(stc, stc_in, sizeof(struct sctp_state_cookie));
/* tack the INIT and then the INIT-ACK onto the chain */
cookie_sz = 0;

View File

@ -3498,140 +3498,22 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
case SCTP_BINDX_ADD_ADDR:
{
struct sctp_getaddresses *addrs;
struct sockaddr *addr_touse;
struct sockaddr_in sin;
SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
/* see if we're bound all already! */
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
error = EINVAL;
break;
}
/* Is the VRF one we have */
addr_touse = addrs->addr;
#if defined(INET6)
if (addrs->addr->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6;
if (addrs->addr->sa_len != sizeof(struct sockaddr_in6)) {
error = EINVAL;
break;
}
sin6 = (struct sockaddr_in6 *)addr_touse;
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
in6_sin6_2_sin(&sin, sin6);
addr_touse = (struct sockaddr *)&sin;
}
}
#endif
if (addrs->addr->sa_family == AF_INET) {
if (addrs->addr->sa_len != sizeof(struct sockaddr_in)) {
error = EINVAL;
break;
}
}
if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
if (p == NULL) {
/* Can't get proc for Net/Open BSD */
error = EINVAL;
break;
}
error = sctp_inpcb_bind(so, addr_touse, p);
break;
}
/*
* No locks required here since bind and mgmt_ep_sa
* all do their own locking. If we do something for
* the FIX: below we may need to lock in that case.
*/
if (addrs->sget_assoc_id == 0) {
/* add the address */
struct sctp_inpcb *lep;
((struct sockaddr_in *)addr_touse)->sin_port = inp->sctp_lport;
lep = sctp_pcb_findep(addr_touse, 1, 0, vrf_id);
if (lep != NULL) {
/*
* We must decrement the refcount
* since we have the ep already and
* are binding. No remove going on
* here.
*/
SCTP_INP_DECR_REF(inp);
}
if (lep == inp) {
/* already bound to it.. ok */
break;
} else if (lep == NULL) {
((struct sockaddr_in *)addr_touse)->sin_port = 0;
error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
SCTP_ADD_IP_ADDRESS, vrf_id);
} else {
error = EADDRINUSE;
}
if (error)
break;
} else {
/*
* FIX: decide whether we allow assoc based
* bindx
*/
}
SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
optsize);
sctp_bindx_add_address(so, inp, addrs->addr,
addrs->sget_assoc_id, vrf_id,
&error, p);
}
break;
case SCTP_BINDX_REM_ADDR:
{
struct sctp_getaddresses *addrs;
struct sockaddr *addr_touse;
struct sockaddr_in sin;
SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
/* see if we're bound all already! */
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
error = EINVAL;
break;
}
addr_touse = addrs->addr;
#if defined(INET6)
if (addrs->addr->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6;
if (addrs->addr->sa_len != sizeof(struct sockaddr_in6)) {
error = EINVAL;
break;
}
sin6 = (struct sockaddr_in6 *)addr_touse;
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
in6_sin6_2_sin(&sin, sin6);
addr_touse = (struct sockaddr *)&sin;
}
}
#endif
if (addrs->addr->sa_family == AF_INET) {
if (addrs->addr->sa_len != sizeof(struct sockaddr_in)) {
error = EINVAL;
break;
}
}
/*
* No lock required mgmt_ep_sa does its own locking.
* If the FIX: below is ever changed we may need to
* lock before calling association level binding.
*/
if (addrs->sget_assoc_id == 0) {
/* delete the address */
error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
SCTP_DEL_IP_ADDRESS,
vrf_id);
} else {
/*
* FIX: decide whether we allow assoc based
* bindx
*/
}
sctp_bindx_delete_address(so, inp, addrs->addr,
addrs->sget_assoc_id, vrf_id,
&error);
}
break;
default:

View File

@ -5877,3 +5877,147 @@ sctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr,
}
return ((struct sctp_tcb *)NULL);
}
/*
* sctp_bindx(ADD) for one address.
* assumes all arguments are valid/checked by caller.
*/
void
sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp,
struct sockaddr *sa, sctp_assoc_t assoc_id,
uint32_t vrf_id, int *error, void *p)
{
struct sockaddr *addr_touse;
struct sockaddr_in sin;
/* see if we're bound all already! */
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
*error = EINVAL;
return;
}
addr_touse = sa;
#if defined(INET6)
if (sa->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6;
if (sa->sa_len != sizeof(struct sockaddr_in6)) {
*error = EINVAL;
return;
}
sin6 = (struct sockaddr_in6 *)addr_touse;
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
in6_sin6_2_sin(&sin, sin6);
addr_touse = (struct sockaddr *)&sin;
}
}
#endif
if (sa->sa_family == AF_INET) {
if (sa->sa_len != sizeof(struct sockaddr_in)) {
*error = EINVAL;
return;
}
}
if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
if (p == NULL) {
/* Can't get proc for Net/Open BSD */
*error = EINVAL;
return;
}
*error = sctp_inpcb_bind(so, addr_touse, p);
return;
}
/*
* No locks required here since bind and mgmt_ep_sa all do their own
* locking. If we do something for the FIX: below we may need to
* lock in that case.
*/
if (assoc_id == 0) {
/* add the address */
struct sctp_inpcb *lep;
((struct sockaddr_in *)addr_touse)->sin_port = inp->sctp_lport;
lep = sctp_pcb_findep(addr_touse, 1, 0, vrf_id);
if (lep != NULL) {
/*
* We must decrement the refcount since we have the
* ep already and are binding. No remove going on
* here.
*/
SCTP_INP_DECR_REF(inp);
}
if (lep == inp) {
/* already bound to it.. ok */
return;
} else if (lep == NULL) {
((struct sockaddr_in *)addr_touse)->sin_port = 0;
*error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
SCTP_ADD_IP_ADDRESS,
vrf_id);
} else {
*error = EADDRINUSE;
}
if (*error)
return;
} else {
/*
* FIX: decide whether we allow assoc based bindx
*/
}
}
/*
* sctp_bindx(DELETE) for one address.
* assumes all arguments are valid/checked by caller.
*/
void
sctp_bindx_delete_address(struct socket *so, struct sctp_inpcb *inp,
struct sockaddr *sa, sctp_assoc_t assoc_id,
uint32_t vrf_id, int *error)
{
struct sockaddr *addr_touse;
struct sockaddr_in sin;
/* see if we're bound all already! */
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
*error = EINVAL;
return;
}
addr_touse = sa;
#if defined(INET6)
if (sa->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6;
if (sa->sa_len != sizeof(struct sockaddr_in6)) {
*error = EINVAL;
return;
}
sin6 = (struct sockaddr_in6 *)addr_touse;
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
in6_sin6_2_sin(&sin, sin6);
addr_touse = (struct sockaddr *)&sin;
}
}
#endif
if (sa->sa_family == AF_INET) {
if (sa->sa_len != sizeof(struct sockaddr_in)) {
*error = EINVAL;
return;
}
}
/*
* No lock required mgmt_ep_sa does its own locking. If the FIX:
* below is ever changed we may need to lock before calling
* association level binding.
*/
if (assoc_id == 0) {
/* delete the address */
*error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
SCTP_DEL_IP_ADDRESS,
vrf_id);
} else {
/*
* FIX: decide whether we allow assoc based bindx
*/
}
}

View File

@ -264,6 +264,14 @@ sctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *,
struct mbuf *sctp_generate_invmanparam(int);
void
sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp,
struct sockaddr *sa, sctp_assoc_t assoc_id,
uint32_t vrf_id, int *error, void *p);
void
sctp_bindx_delete_address(struct socket *so, struct sctp_inpcb *inp,
struct sockaddr *sa, sctp_assoc_t assoc_id,
uint32_t vrf_id, int *error);
#ifdef SCTP_MBCNT_LOGGING
void

View File

@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$");
SYSCTL_DECL(_net_inet6_sctp6);
extern struct pr_usrreqs sctp6_usrreqs;
int sctp6_ctloutput __P((struct socket *, struct sockopt *));
int sctp6_input __P((struct mbuf **, int *, int));