lib: Breakout sendmmsg into it's own header

The only 2 places sendmmsg is used is in zlog_5424.c
and zlog_live.c.  Why is the rest of the entire system
paying for this compilation?

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2024-01-04 13:55:09 -05:00
parent 4e249eb2e4
commit 10387101fe
5 changed files with 35 additions and 20 deletions

30
lib/frrsendmmsg.h Normal file
View file

@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* FRR sendmmsg wrapper
* Copyright (C) 2024 by Nvidia, Inc.
* Donald Sharp
*/
#ifndef __FRRSENDMMSG_H__
#define __FRRSENDMMSG_H__
#if !defined(HAVE_STRUCT_MMSGHDR_MSG_HDR) || !defined(HAVE_SENDMMSG)
/* avoid conflicts in case we have partial support */
#define mmsghdr frr_mmsghdr
#define sendmmsg frr_sendmmsg
struct mmsghdr {
struct msghdr msg_hdr;
unsigned int msg_len;
};
/* just go 1 at a time here, the loop this is used in will handle the rest */
static inline int sendmmsg(int fd, struct mmsghdr *mmh, unsigned int len,
int flags)
{
int rv = sendmsg(fd, &mmh->msg_hdr, 0);
return rv > 0 ? 1 : rv;
}
#endif
#endif

View file

@ -227,6 +227,7 @@ pkginclude_HEADERS += \
lib/frr_pthread.h \ lib/frr_pthread.h \
lib/frratomic.h \ lib/frratomic.h \
lib/frrcu.h \ lib/frrcu.h \
lib/frrsendmmsg.h \
lib/frrstr.h \ lib/frrstr.h \
lib/graph.h \ lib/graph.h \
lib/hash.h \ lib/hash.h \

View file

@ -203,26 +203,6 @@ size_t strlcpy(char *__restrict dest,
void explicit_bzero(void *buf, size_t len); void explicit_bzero(void *buf, size_t len);
#endif #endif
#if !defined(HAVE_STRUCT_MMSGHDR_MSG_HDR) || !defined(HAVE_SENDMMSG)
/* avoid conflicts in case we have partial support */
#define mmsghdr frr_mmsghdr
#define sendmmsg frr_sendmmsg
struct mmsghdr {
struct msghdr msg_hdr;
unsigned int msg_len;
};
/* just go 1 at a time here, the loop this is used in will handle the rest */
static inline int sendmmsg(int fd, struct mmsghdr *mmh, unsigned int len,
int flags)
{
int rv = sendmsg(fd, &mmh->msg_hdr, 0);
return rv > 0 ? 1 : rv;
}
#endif
/* /*
* RFC 3542 defines several macros for using struct cmsghdr. * RFC 3542 defines several macros for using struct cmsghdr.
* Here, we define those that are not present * Here, we define those that are not present

View file

@ -14,6 +14,8 @@
#include "zebra.h" #include "zebra.h"
#include "frrsendmmsg.h"
#include "zlog_5424.h" #include "zlog_5424.h"
#include <sys/un.h> #include <sys/un.h>

View file

@ -5,6 +5,8 @@
#include "zebra.h" #include "zebra.h"
#include "frrsendmmsg.h"
#include "zlog_live.h" #include "zlog_live.h"
#include "memory.h" #include "memory.h"