9
0
Fork 0

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.
This commit is contained in:
Holger Hans Peter Freyther 2011-02-25 19:42:51 +01:00
parent 639d77b6fb
commit 0e6cbc62b2
1 changed files with 10 additions and 5 deletions

View File

@ -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;
}