diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-02-25 19:42:51 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-02-25 19:44:22 +0100 |
commit | 0e6cbc62b23f5035dcd3a958bc00509441936adb (patch) | |
tree | 024f23a421111ef897c9b243c320850bfe5f20a5 | |
parent | 639d77b6fbf2e8d81b621dd42b85dc3d1e23028e (diff) |
sctp: Fail if we fail to enable SCTP events on this socket
Without events we don't have access to the SCTP sndrcvinfo and
the ppid in it and we will do bad things like sending M2UA on
PPID 0.
-rw-r--r-- | src/sctp_m2ua.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/sctp_m2ua.c b/src/sctp_m2ua.c index d0609dd..9ffcebc 100644 --- a/src/sctp_m2ua.c +++ b/src/sctp_m2ua.c @@ -632,7 +632,7 @@ static int sctp_trans_accept(struct bsc_fd *fd, unsigned int what) struct sctp_m2ua_conn *conn; struct sockaddr_in addr; socklen_t len; - int s; + int s, ret; len = sizeof(addr); s = accept(fd->fd, (struct sockaddr *) &addr, &len); @@ -648,6 +648,15 @@ static int sctp_trans_accept(struct bsc_fd *fd, unsigned int what) return -1; } + memset(&events, 0, sizeof(events)); + events.sctp_data_io_event = 1; + ret = setsockopt(s, SOL_SCTP, SCTP_EVENTS, &events, sizeof(events)); + if (ret != 0) { + LOGP(DINP, LOGL_ERROR, "Failed to enable SCTP Events. Closing socket.\n"); + close(s); + return -1; + } + LOGP(DINP, LOGL_NOTICE, "Got a new SCTP connection.\n"); conn = talloc_zero(fd->data, struct sctp_m2ua_conn); if (!conn) { @@ -672,10 +681,6 @@ static int sctp_trans_accept(struct bsc_fd *fd, unsigned int what) return -1; } - memset(&events, 0, sizeof(events)); - events.sctp_data_io_event = 1; - setsockopt(s, SOL_SCTP, SCTP_EVENTS, &events, sizeof(events)); - llist_add_tail(&conn->entry, &trans->conns); return 0; } |