Skip to content

Commit c0425a4

Browse files
Christoph Hellwigdavem330
authored andcommitted
net: add a new bind_add method
The SCTP protocol allows to bind multiple address to a socket. That feature is currently only exposed as a socket option. Add a bind_add method struct proto that allows to bind additional addresses, and switch the dlm code to use the method instead of going through the socket option from kernel space. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 05bfd36 commit c0425a4

4 files changed

Lines changed: 30 additions & 7 deletions

File tree

‎fs/dlm/lowcomms.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -882,20 +882,17 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed)
882882
static int sctp_bind_addrs(struct connection *con, uint16_t port)
883883
{
884884
struct sockaddr_storage localaddr;
885+
struct sockaddr *addr = (struct sockaddr *)&localaddr;
885886
int i, addr_len, result = 0;
886887

887888
for (i = 0; i < dlm_local_count; i++) {
888889
memcpy(&localaddr, dlm_local_addr[i], sizeof(localaddr));
889890
make_sockaddr(&localaddr, port, &addr_len);
890891

891892
if (!i)
892-
result = kernel_bind(con->sock,
893-
(struct sockaddr *)&localaddr,
894-
addr_len);
893+
result = kernel_bind(con->sock, addr, addr_len);
895894
else
896-
result = kernel_setsockopt(con->sock, SOL_SCTP,
897-
SCTP_SOCKOPT_BINDX_ADD,
898-
(char *)&localaddr, addr_len);
895+
result = sock_bind_add(con->sock->sk, addr, addr_len);
899896

900897
if (result < 0) {
901898
log_print("Can't bind to %d addr number %d, %d.\n",

‎include/net/sock.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,9 @@ struct proto {
11561156
int (*sendpage)(struct sock *sk, struct page *page,
11571157
int offset, size_t size, int flags);
11581158
int (*bind)(struct sock *sk,
1159-
struct sockaddr *uaddr, int addr_len);
1159+
struct sockaddr *addr, int addr_len);
1160+
int (*bind_add)(struct sock *sk,
1161+
struct sockaddr *addr, int addr_len);
11601162

11611163
int (*backlog_rcv) (struct sock *sk,
11621164
struct sk_buff *skb);
@@ -2698,4 +2700,6 @@ void sock_set_reuseaddr(struct sock *sk);
26982700
void sock_set_reuseport(struct sock *sk);
26992701
void sock_set_sndtimeo(struct sock *sk, s64 secs);
27002702

2703+
int sock_bind_add(struct sock *sk, struct sockaddr *addr, int addr_len);
2704+
27012705
#endif /* _SOCK_H */

‎net/core/sock.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,3 +3712,11 @@ bool sk_busy_loop_end(void *p, unsigned long start_time)
37123712
}
37133713
EXPORT_SYMBOL(sk_busy_loop_end);
37143714
#endif /* CONFIG_NET_RX_BUSY_POLL */
3715+
3716+
int sock_bind_add(struct sock *sk, struct sockaddr *addr, int addr_len)
3717+
{
3718+
if (!sk->sk_prot->bind_add)
3719+
return -EOPNOTSUPP;
3720+
return sk->sk_prot->bind_add(sk, addr, addr_len);
3721+
}
3722+
EXPORT_SYMBOL(sock_bind_add);

‎net/sctp/socket.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,18 @@ static int sctp_setsockopt_bindx(struct sock *sk,
10521052
return err;
10531053
}
10541054

1055+
static int sctp_bind_add(struct sock *sk, struct sockaddr *addrs,
1056+
int addrlen)
1057+
{
1058+
int err;
1059+
1060+
lock_sock(sk);
1061+
err = sctp_setsockopt_bindx_kernel(sk, addrs, addrlen,
1062+
SCTP_BINDX_ADD_ADDR);
1063+
release_sock(sk);
1064+
return err;
1065+
}
1066+
10551067
static int sctp_connect_new_asoc(struct sctp_endpoint *ep,
10561068
const union sctp_addr *daddr,
10571069
const struct sctp_initmsg *init,
@@ -9620,6 +9632,7 @@ struct proto sctp_prot = {
96209632
.sendmsg = sctp_sendmsg,
96219633
.recvmsg = sctp_recvmsg,
96229634
.bind = sctp_bind,
9635+
.bind_add = sctp_bind_add,
96239636
.backlog_rcv = sctp_backlog_rcv,
96249637
.hash = sctp_hash,
96259638
.unhash = sctp_unhash,
@@ -9662,6 +9675,7 @@ struct proto sctpv6_prot = {
96629675
.sendmsg = sctp_sendmsg,
96639676
.recvmsg = sctp_recvmsg,
96649677
.bind = sctp_bind,
9678+
.bind_add = sctp_bind_add,
96659679
.backlog_rcv = sctp_backlog_rcv,
96669680
.hash = sctp_hash,
96679681
.unhash = sctp_unhash,

0 commit comments

Comments
 (0)