Skip to content

Commit

Permalink
Socket flag to allow udp fragmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nikbyte committed May 17, 2022
1 parent ea98864 commit 1061fbf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cfg.lex
Expand Up @@ -326,6 +326,7 @@ CR \n
ANY "any"
ANYCAST "anycast"
FRAG "frag"
COM_LINE #
Expand Down Expand Up @@ -581,6 +582,7 @@ SPACE [ ]
<INITIAL>{CR} { count();/* return CR;*/ }
<INITIAL>{ANY} { count(); return ANY; }
<INITIAL>{ANYCAST} { count(); return ANYCAST; }
<INITIAL>{FRAG} { count(); return FRAG; }
<INITIAL>{SLASH} { count(); return SLASH; }
<INITIAL>{SCALE_UP_TO} { count(); return SCALE_UP_TO; }
<INITIAL>{SCALE_DOWN_TO} { count(); return SCALE_DOWN_TO; }
Expand Down
4 changes: 4 additions & 0 deletions cfg.y
Expand Up @@ -430,6 +430,7 @@ extern int cfg_parse_only_routes;
%token COLON
%token ANY
%token ANYCAST
%token FRAG
%token SCRIPTVARERR
%token SCALE_UP_TO
%token SCALE_DOWN_TO
Expand Down Expand Up @@ -636,6 +637,9 @@ listen_id_def: listen_id { IFOR();
socket_def_param: ANYCAST { IFOR();
p_tmp.flags |= SI_IS_ANYCAST;
}
| FRAG { IFOR();
p_tmp.flags |= SI_FRAG;
}
| USE_WORKERS NUMBER { IFOR();
p_tmp.workers=$2;
}
Expand Down
2 changes: 1 addition & 1 deletion ip_addr.h
Expand Up @@ -89,7 +89,7 @@ union sockaddr_union{


enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4,
SI_IS_ANYCAST=8 };
SI_IS_ANYCAST=8, SI_FRAG=16 };

struct receive_info {
struct ip_addr src_ip;
Expand Down
7 changes: 7 additions & 0 deletions net/net_udp.c
Expand Up @@ -179,6 +179,13 @@ int udp_init_listener(struct socket_info *si, int status_flags)
LM_ERR("setsockopt: %s\n", strerror(errno));
goto error;
}

if (si->flags & SI_FRAG) {
/* no DF */
optval = IP_PMTUDISC_DONT;
setsockopt(si->socket, IPPROTO_IP, IP_MTU_DISCOVER, (void*)&optval, sizeof(optval));
}

/* tos */
optval=tos;
if (addr->s.sa_family==AF_INET6){
Expand Down
3 changes: 2 additions & 1 deletion net/trans.c
Expand Up @@ -264,9 +264,10 @@ void print_all_socket_lists(void)
continue;

for (si = protos[i].listeners; si; si = si->next)
printf(" %s: %s [%s]:%s%s%s\n", protos[i].name,
printf(" %s: %s [%s]:%s%s%s%s\n", protos[i].name,
si->name.s, si->address_str.s, si->port_no_str.s,
si->flags & SI_IS_MCAST ? " mcast" : "",
si->flags & SI_FRAG ? " allow_fragments" : "",
is_anycast(si)? " anycast" : "");
}
}

0 comments on commit 1061fbf

Please sign in to comment.