udp: Avoid static initialiser for udp{4,6}_l2_buf

With the new UDP_TAP_FRAMES value, the binary size grows considerably.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-10-21 04:49:25 +02:00
parent 85a80f8f63
commit 27f5999677

41
udp.c
View file

@ -193,7 +193,7 @@ static uint8_t udp_act[IP_VERSIONS][UDP_ACT_TYPE_MAX][USHRT_MAX / 8];
* @uh: Headroom for UDP header * @uh: Headroom for UDP header
* @data: Storage for UDP payload * @data: Storage for UDP payload
*/ */
__extension__ static struct udp4_l2_buf_t { static struct udp4_l2_buf_t {
struct sockaddr_in s_in; struct sockaddr_in s_in;
uint32_t psum; uint32_t psum;
@ -204,12 +204,7 @@ __extension__ static struct udp4_l2_buf_t {
uint8_t data[USHRT_MAX - uint8_t data[USHRT_MAX -
(sizeof(struct iphdr) + sizeof(struct udphdr))]; (sizeof(struct iphdr) + sizeof(struct udphdr))];
} __attribute__ ((packed, aligned(__alignof__(unsigned int)))) } __attribute__ ((packed, aligned(__alignof__(unsigned int))))
udp4_l2_buf[UDP_TAP_FRAMES] = { udp4_l2_buf[UDP_TAP_FRAMES];
[ 0 ... UDP_TAP_FRAMES - 1 ] = {
{ 0 }, 0, 0, L2_BUF_ETH_IP4_INIT, L2_BUF_IP4_INIT(IPPROTO_UDP),
{{{ 0 }}}, { 0 },
},
};
/** /**
* udp6_l2_buf_t - Pre-cooked IPv6 packet buffers for tap connections * udp6_l2_buf_t - Pre-cooked IPv6 packet buffers for tap connections
@ -220,7 +215,7 @@ udp4_l2_buf[UDP_TAP_FRAMES] = {
* @uh: Headroom for UDP header * @uh: Headroom for UDP header
* @data: Storage for UDP payload * @data: Storage for UDP payload
*/ */
__extension__ struct udp6_l2_buf_t { struct udp6_l2_buf_t {
struct sockaddr_in6 s_in6; struct sockaddr_in6 s_in6;
#ifdef __AVX2__ #ifdef __AVX2__
/* Align ip6h to 32-byte boundary. */ /* Align ip6h to 32-byte boundary. */
@ -239,16 +234,7 @@ __extension__ struct udp6_l2_buf_t {
#else #else
} __attribute__ ((packed, aligned(__alignof__(unsigned int)))) } __attribute__ ((packed, aligned(__alignof__(unsigned int))))
#endif #endif
udp6_l2_buf[UDP_TAP_FRAMES] = { udp6_l2_buf[UDP_TAP_FRAMES];
[ 0 ... UDP_TAP_FRAMES - 1 ] = {
{ 0 },
#ifdef __AVX2__
{ 0 },
#endif
0, L2_BUF_ETH_IP6_INIT, L2_BUF_IP6_INIT(IPPROTO_UDP),
{{{ 0 }}}, { 0 },
},
};
static struct sockaddr_storage udp_splice_namebuf; static struct sockaddr_storage udp_splice_namebuf;
static uint8_t udp_splice_buf[UDP_SPLICE_FRAMES][USHRT_MAX]; static uint8_t udp_splice_buf[UDP_SPLICE_FRAMES][USHRT_MAX];
@ -360,6 +346,14 @@ static void udp_sock4_iov_init(void)
struct mmsghdr *h; struct mmsghdr *h;
int i; int i;
for (i = 0; i < ARRAY_SIZE(udp4_l2_buf); i++) {
udp4_l2_buf[i] = (struct udp4_l2_buf_t) {
{ 0 }, 0, 0,
L2_BUF_ETH_IP4_INIT, L2_BUF_IP4_INIT(IPPROTO_UDP),
{{{ 0 }}}, { 0 },
};
}
for (i = 0, h = udp4_l2_mh_sock; i < UDP_TAP_FRAMES; i++, h++) { for (i = 0, h = udp4_l2_mh_sock; i < UDP_TAP_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr; struct msghdr *mh = &h->msg_hdr;
@ -389,6 +383,17 @@ static void udp_sock6_iov_init(void)
struct mmsghdr *h; struct mmsghdr *h;
int i; int i;
for (i = 0; i < ARRAY_SIZE(udp6_l2_buf); i++) {
udp6_l2_buf[i] = (struct udp6_l2_buf_t) {
{ 0 },
#ifdef __AVX2__
{ 0 },
#endif
0, L2_BUF_ETH_IP6_INIT, L2_BUF_IP6_INIT(IPPROTO_UDP),
{{{ 0 }}}, { 0 },
};
}
for (i = 0, h = udp6_l2_mh_sock; i < UDP_TAP_FRAMES; i++, h++) { for (i = 0, h = udp6_l2_mh_sock; i < UDP_TAP_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr; struct msghdr *mh = &h->msg_hdr;