Deleted Added
full compact
sctp_sys_calls.c (171440) sctp_sys_calls.c (171572)
1/* $KAME: sctp_sys_calls.c,v 1.9 2004/08/17 06:08:53 itojun Exp $ */
2
3/*
4 * Copyright (C) 2002-2007 Cisco Systems Inc,
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 15 unchanged lines hidden (view full) ---

24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#include <sys/cdefs.h>
1/* $KAME: sctp_sys_calls.c,v 1.9 2004/08/17 06:08:53 itojun Exp $ */
2
3/*
4 * Copyright (C) 2002-2007 Cisco Systems Inc,
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 15 unchanged lines hidden (view full) ---

24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/lib/libc/net/sctp_sys_calls.c 171440 2007-07-14 09:36:28Z rrs $");
32__FBSDID("$FreeBSD: head/lib/libc/net/sctp_sys_calls.c 171572 2007-07-24 20:06:02Z rrs $");
33#include <stdio.h>
34#include <string.h>
35#include <errno.h>
36#include <stdlib.h>
37#include <unistd.h>
38#include <sys/types.h>
39#include <sys/socket.h>
40#include <sys/errno.h>

--- 194 unchanged lines hidden (view full) ---

235 return (ret);
236}
237
238int
239sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags)
240{
241 struct sctp_getaddresses *gaddrs;
242 struct sockaddr *sa;
33#include <stdio.h>
34#include <string.h>
35#include <errno.h>
36#include <stdlib.h>
37#include <unistd.h>
38#include <sys/types.h>
39#include <sys/socket.h>
40#include <sys/errno.h>

--- 194 unchanged lines hidden (view full) ---

235 return (ret);
236}
237
238int
239sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags)
240{
241 struct sctp_getaddresses *gaddrs;
242 struct sockaddr *sa;
243 struct sockaddr_in *sin;
244 struct sockaddr_in6 *sin6;
243 int i, sz, argsz;
245 int i, sz, argsz;
246 uint16_t sport = 0;
244
245 /* validate the flags */
246 if ((flags != SCTP_BINDX_ADD_ADDR) &&
247 (flags != SCTP_BINDX_REM_ADDR)) {
248 errno = EFAULT;
249 return (-1);
250 }
251 /* validate the address count and list */
252 if ((addrcnt <= 0) || (addrs == NULL)) {
253 errno = EINVAL;
254 return (-1);
255 }
256 argsz = (sizeof(struct sockaddr_storage) +
257 sizeof(struct sctp_getaddresses));
258 gaddrs = (struct sctp_getaddresses *)calloc(1, argsz);
259 if (gaddrs == NULL) {
260 errno = ENOMEM;
261 return (-1);
262 }
247
248 /* validate the flags */
249 if ((flags != SCTP_BINDX_ADD_ADDR) &&
250 (flags != SCTP_BINDX_REM_ADDR)) {
251 errno = EFAULT;
252 return (-1);
253 }
254 /* validate the address count and list */
255 if ((addrcnt <= 0) || (addrs == NULL)) {
256 errno = EINVAL;
257 return (-1);
258 }
259 argsz = (sizeof(struct sockaddr_storage) +
260 sizeof(struct sctp_getaddresses));
261 gaddrs = (struct sctp_getaddresses *)calloc(1, argsz);
262 if (gaddrs == NULL) {
263 errno = ENOMEM;
264 return (-1);
265 }
266 /* First pre-screen the addresses */
263 sa = addrs;
264 for (i = 0; i < addrcnt; i++) {
265 sz = sa->sa_len;
266 if (sa->sa_family == AF_INET) {
267 if (sa->sa_len != sizeof(struct sockaddr_in))
268 goto out_error;
267 sa = addrs;
268 for (i = 0; i < addrcnt; i++) {
269 sz = sa->sa_len;
270 if (sa->sa_family == AF_INET) {
271 if (sa->sa_len != sizeof(struct sockaddr_in))
272 goto out_error;
273 sin = (struct sockaddr_in *)sa;
274 if (sin->sin_port) {
275 /* non-zero port, check or save */
276 if (sport) {
277 /* Check against our port */
278 if (sport != sin->sin_port) {
279 goto out_error;
280 }
281 } else {
282 /* save off the port */
283 sport = sin->sin_port;
284 }
285 }
269 } else if (sa->sa_family == AF_INET6) {
270 if (sa->sa_len != sizeof(struct sockaddr_in6))
271 goto out_error;
286 } else if (sa->sa_family == AF_INET6) {
287 if (sa->sa_len != sizeof(struct sockaddr_in6))
288 goto out_error;
289 sin6 = (struct sockaddr_in6 *)sa;
290 if (sin6->sin6_port) {
291 /* non-zero port, check or save */
292 if (sport) {
293 /* Check against our port */
294 if (sport != sin6->sin6_port) {
295 goto out_error;
296 }
297 } else {
298 /* save off the port */
299 sport = sin6->sin6_port;
300 }
301 }
272 } else {
273 /* invalid address family specified */
302 } else {
303 /* invalid address family specified */
304 goto out_error;
305 }
306
307
308 }
309 sa = addrs;
310 /*
311 * Now if there was a port mentioned, assure that the first address
312 * has that port to make sure it fails or succeeds correctly.
313 */
314 if (sport) {
315 sin = (struct sockaddr_in *)sa;
316 sin->sin_port = sport;
317 }
318 for (i = 0; i < addrcnt; i++) {
319 sz = sa->sa_len;
320 if (sa->sa_family == AF_INET) {
321 if (sa->sa_len != sizeof(struct sockaddr_in))
322 goto out_error;
323 } else if (sa->sa_family == AF_INET6) {
324 if (sa->sa_len != sizeof(struct sockaddr_in6))
325 goto out_error;
326 } else {
327 /* invalid address family specified */
274 out_error:
275 free(gaddrs);
276 errno = EINVAL;
277 return (-1);
278 }
279 memset(gaddrs, 0, argsz);
280 gaddrs->sget_assoc_id = 0;
281 memcpy(gaddrs->addr, sa, sz);

--- 11 unchanged lines hidden (view full) ---

293
294int
295sctp_opt_info(int sd, sctp_assoc_t id, int opt, void *arg, socklen_t * size)
296{
297 if (arg == NULL) {
298 errno = EINVAL;
299 return (-1);
300 }
328 out_error:
329 free(gaddrs);
330 errno = EINVAL;
331 return (-1);
332 }
333 memset(gaddrs, 0, argsz);
334 gaddrs->sget_assoc_id = 0;
335 memcpy(gaddrs->addr, sa, sz);

--- 11 unchanged lines hidden (view full) ---

347
348int
349sctp_opt_info(int sd, sctp_assoc_t id, int opt, void *arg, socklen_t * size)
350{
351 if (arg == NULL) {
352 errno = EINVAL;
353 return (-1);
354 }
301 *(sctp_assoc_t *) arg = id;
355 switch (opt) {
356 case SCTP_RTOINFO:
357 ((struct sctp_rtoinfo *)arg)->srto_assoc_id = id;
358 break;
359 case SCTP_ASSOCINFO:
360 ((struct sctp_assocparams *)arg)->sasoc_assoc_id = id;
361 break;
362 case SCTP_DEFAULT_SEND_PARAM:
363 ((struct sctp_assocparams *)arg)->sasoc_assoc_id = id;
364 break;
365 case SCTP_SET_PEER_PRIMARY_ADDR:
366 ((struct sctp_setpeerprim *)arg)->sspp_assoc_id = id;
367 break;
368 case SCTP_PRIMARY_ADDR:
369 ((struct sctp_setprim *)arg)->ssp_assoc_id = id;
370 break;
371 case SCTP_PEER_ADDR_PARAMS:
372 ((struct sctp_paddrparams *)arg)->spp_assoc_id = id;
373 break;
374 case SCTP_MAXSEG:
375 ((struct sctp_assoc_value *)arg)->assoc_id = id;
376 break;
377 case SCTP_AUTH_KEY:
378 ((struct sctp_authkey *)arg)->sca_assoc_id = id;
379 break;
380 case SCTP_AUTH_ACTIVE_KEY:
381 ((struct sctp_authkeyid *)arg)->scact_assoc_id = id;
382 break;
383 case SCTP_DELAYED_SACK:
384 ((struct sctp_sack_info *)arg)->sack_assoc_id = id;
385 break;
386 case SCTP_CONTEXT:
387 ((struct sctp_assoc_value *)arg)->assoc_id = id;
388 break;
389 case SCTP_STATUS:
390 ((struct sctp_status *)arg)->sstat_assoc_id = id;
391 break;
392 case SCTP_GET_PEER_ADDR_INFO:
393 ((struct sctp_paddrinfo *)arg)->spinfo_assoc_id = id;
394 break;
395 case SCTP_PEER_AUTH_CHUNKS:
396 ((struct sctp_authchunks *)arg)->gauth_assoc_id = id;
397 break;
398 case SCTP_LOCAL_AUTH_CHUNKS:
399 ((struct sctp_authchunks *)arg)->gauth_assoc_id = id;
400 break;
401 default:
402 break;
403 }
302 return (getsockopt(sd, IPPROTO_SCTP, opt, arg, size));
303}
304
305int
306sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs)
307{
308 struct sctp_getaddresses *addrs;
309 struct sockaddr *sa;

--- 313 unchanged lines hidden (view full) ---

623 int flags)
624{
625 ssize_t ret;
626 int i, cnt, *aa, saved_errno;
627 char *buf;
628 int add_len, len, no_end_cx = 0;
629 struct sockaddr *at;
630
404 return (getsockopt(sd, IPPROTO_SCTP, opt, arg, size));
405}
406
407int
408sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs)
409{
410 struct sctp_getaddresses *addrs;
411 struct sockaddr *sa;

--- 313 unchanged lines hidden (view full) ---

725 int flags)
726{
727 ssize_t ret;
728 int i, cnt, *aa, saved_errno;
729 char *buf;
730 int add_len, len, no_end_cx = 0;
731 struct sockaddr *at;
732
631
733 if (addrs == NULL) {
734 errno = EINVAL;
735 return (-1);
736 }
632#ifdef SYS_sctp_generic_sendmsg
633 if (addrcnt < SCTP_SMALL_IOVEC_SIZE) {
634 socklen_t l;
635
636 /*
637 * Quick way, we don't need to do a connectx so lets use the
638 * syscall directly.
639 */
640 l = addrs->sa_len;
641 return (syscall(SYS_sctp_generic_sendmsg, sd,
642 msg, msg_len, addrs, l, sinfo, flags));
643 }
644#endif
645
737#ifdef SYS_sctp_generic_sendmsg
738 if (addrcnt < SCTP_SMALL_IOVEC_SIZE) {
739 socklen_t l;
740
741 /*
742 * Quick way, we don't need to do a connectx so lets use the
743 * syscall directly.
744 */
745 l = addrs->sa_len;
746 return (syscall(SYS_sctp_generic_sendmsg, sd,
747 msg, msg_len, addrs, l, sinfo, flags));
748 }
749#endif
750
646 if (addrs == NULL) {
647 errno = EINVAL;
648 return (-1);
649 }
650 len = sizeof(int);
651 at = addrs;
652 cnt = 0;
653 /* validate all the addresses and get the size */
654 for (i = 0; i < addrcnt; i++) {
655 if (at->sa_family == AF_INET) {
656 add_len = sizeof(struct sockaddr_in);
657 } else if (at->sa_family == AF_INET6) {

--- 224 unchanged lines hidden ---
751 len = sizeof(int);
752 at = addrs;
753 cnt = 0;
754 /* validate all the addresses and get the size */
755 for (i = 0; i < addrcnt; i++) {
756 if (at->sa_family == AF_INET) {
757 add_len = sizeof(struct sockaddr_in);
758 } else if (at->sa_family == AF_INET6) {

--- 224 unchanged lines hidden ---