Skip to content

Commit

Permalink
Network socket options: add support for IPPROTO_IP/IP_MTU_DISCOVER
Browse files Browse the repository at this point in the history
This socket option controls the setting of the DF (don't fragment)
flag in output IPv4 packets.
Depends on nanovms/lwip#14.
  • Loading branch information
francescolavra committed Oct 19, 2024
1 parent 4c77f77 commit 7f80293
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/net/netsyscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ static inline s64 lwip_to_errno(s8 err)
case ERR_RST: return -ECONNRESET;
case ERR_CLSD: return -ENOTCONN;
case ERR_ARG: return -EIO;
case ERR_MSGSIZE: return -EMSGSIZE;
}
return -EINVAL; /* XXX unknown - check return value */
}
Expand Down Expand Up @@ -2386,6 +2387,24 @@ static sysreturn netsock_setsockopt(struct sock *sock, int level,
int int_optval;
sysreturn rv;
switch (level) {
case IPPROTO_IP:
switch (optname) {
case IP_MTU_DISCOVER:
rv = sockopt_copy_from_user(optval, optlen, &int_optval, sizeof(int));
if (rv)
goto out;
if (s->sock.type == SOCK_STREAM) {
struct tcp_pcb *tcp_lw = netsock_tcp_get(s);
tcp_lw->pmtudisc = int_optval;
netsock_tcp_put(tcp_lw);
} else {
s->info.udp.lw->pmtudisc = int_optval;
}
break;
default:
goto unimplemented;
}
break;
case IPPROTO_IPV6:
switch (optname) {
case IPV6_V6ONLY:
Expand Down Expand Up @@ -2696,6 +2715,21 @@ static sysreturn netsock_getsockopt(struct sock *sock, int level,
goto unimplemented;
}
break;
case IPPROTO_IP:
switch (optname) {
case IP_MTU_DISCOVER:
if (s->sock.type == SOCK_STREAM) {
struct tcp_pcb *tcp_lw = netsock_tcp_get(s);
ret_optval.val = tcp_lw->pmtudisc;
netsock_tcp_put(tcp_lw);
} else {
ret_optval.val = s->info.udp.lw->pmtudisc;
}
break;
default:
goto unimplemented;
}
break;
case IPPROTO_IPV6:
switch (optname) {
case IPV6_V6ONLY:
Expand Down
1 change: 1 addition & 0 deletions src/unix/system_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ struct io_uring_params {
#define IP_TOS 1
#define IP_TTL 2
#define IP_OPTIONS 4
#define IP_MTU_DISCOVER 10
#define IP_MINTTL 21
#define IP_MULTICAST_IF 32
#define IP_MULTICAST_TTL 33
Expand Down

0 comments on commit 7f80293

Please sign in to comment.