Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lib zebra h cleanup #15092

Merged
merged 14 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bfdd/bfd_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

#include <zebra.h>
#include <sys/ioctl.h>

#ifdef GNU_LINUX
#include <linux/filter.h>
Expand Down
24 changes: 1 addition & 23 deletions bgpd/rfapi/rfapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
#include "bgpd/rfapi/rfapi_encap_tlv.h"
#include "bgpd/rfapi/vnc_debug.h"

#ifdef HAVE_GLIBC_BACKTRACE
/* for backtrace and friends */
#include <execinfo.h>
#endif /* HAVE_GLIBC_BACKTRACE */

#define DEBUG_CLEANUP 0

struct ethaddr rfapi_ethaddr0 = {{0}};
Expand Down Expand Up @@ -2091,24 +2086,7 @@ int rfapi_close(void *handle)
vnc_zlog_debug_verbose("%s: rfd=%p", __func__, rfd);

#ifdef RFAPI_WHO_IS_CALLING_ME
#ifdef HAVE_GLIBC_BACKTRACE
#define RFAPI_DEBUG_BACKTRACE_NENTRIES 5
{
void *buf[RFAPI_DEBUG_BACKTRACE_NENTRIES];
char **syms;
int i;
size_t size;

size = backtrace(buf, RFAPI_DEBUG_BACKTRACE_NENTRIES);
syms = backtrace_symbols(buf, size);
for (i = 0; i < size && i < RFAPI_DEBUG_BACKTRACE_NENTRIES;
++i) {
vnc_zlog_debug_verbose("backtrace[%2d]: %s", i,
syms[i]);
}
free(syms);
}
#endif
zlog_backtrace(LOG_INFO);
#endif

bgp = rfd->bgp;
Expand Down
33 changes: 1 addition & 32 deletions bgpd/rfapi/rfapi_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
#include "bgpd/rfapi/rfapi_encap_tlv.h"
#include "bgpd/rfapi/vnc_debug.h"

#ifdef HAVE_GLIBC_BACKTRACE
/* for backtrace and friends */
#include <execinfo.h>
#endif /* HAVE_GLIBC_BACKTRACE */

#undef DEBUG_MONITOR_MOVE_SHORTER
#undef DEBUG_RETURNED_NHL
#undef DEBUG_ROUTE_COUNTERS
Expand Down Expand Up @@ -77,32 +72,6 @@ struct rfapi_withdraw {
int lockoffset;
};

/*
* DEBUG FUNCTION
* It's evil and fiendish. It's compiler-dependent.
* ? Might need LDFLAGS -rdynamic to produce all function names
*/
void rfapiDebugBacktrace(void)
{
#ifdef HAVE_GLIBC_BACKTRACE
#define RFAPI_DEBUG_BACKTRACE_NENTRIES 200
void *buf[RFAPI_DEBUG_BACKTRACE_NENTRIES];
char **syms;
size_t i;
size_t size;

size = backtrace(buf, RFAPI_DEBUG_BACKTRACE_NENTRIES);
syms = backtrace_symbols(buf, size);

for (i = 0; i < size && i < RFAPI_DEBUG_BACKTRACE_NENTRIES; ++i) {
vnc_zlog_debug_verbose("backtrace[%2zu]: %s", i, syms[i]);
}

free(syms);
#else
#endif
}

/*
* DEBUG FUNCTION
* Count remote routes and compare with actively-maintained values.
Expand Down Expand Up @@ -1709,7 +1678,7 @@ struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList(

#ifdef DEBUG_RETURNED_NHL
vnc_zlog_debug_verbose("%s: called with node pfx=%rRN", __func__, rn);
rfapiDebugBacktrace();
zlog_backtrace(LOG_INFO);
#endif

rfapiQprefix2Rprefix(p, &rprefix);
Expand Down
2 changes: 0 additions & 2 deletions bgpd/rfapi/rfapi_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ struct rfapi_import_table {

extern uint8_t rfapiRfpCost(struct attr *attr);

extern void rfapiDebugBacktrace(void);

extern void rfapiCheckRouteCount(void);

/*
Expand Down
5 changes: 5 additions & 0 deletions isisd/isis_tlvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include <zebra.h>
#include <json-c/json_object.h>

#ifdef CRYPTO_OPENSSL
#include <openssl/evp.h>
#include <openssl/hmac.h>
#endif

#ifdef CRYPTO_INTERNAL
#include "md5.h"
#endif
Expand Down
1 change: 1 addition & 0 deletions lib/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

#include <zebra.h>
#include <sys/utsname.h>
#include <lib/version.h>

#include "command.h"
Expand Down
30 changes: 30 additions & 0 deletions lib/frrsendmmsg.h
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/imsg-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include <zebra.h>
#include <sys/uio.h>

#include "queue.h"
#include "imsg.h"
Expand Down
4 changes: 4 additions & 0 deletions lib/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#include <zebra.h>

#ifdef HAVE_GLIBC_BACKTRACE
#include <execinfo.h>
#endif /* HAVE_GLIBC_BACKTRACE */

#include "zclient.h"
#include "log.h"
#include "memory.h"
Expand Down
8 changes: 8 additions & 0 deletions lib/privs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
*/
#include <zebra.h>

#include <grp.h>

#ifdef HAVE_LCAPS
#include <sys/capability.h>
#include <sys/prctl.h>
#endif /* HAVE_LCAPS */

#include "log.h"
#include "privs.h"
#include "memory.h"
Expand Down
2 changes: 2 additions & 0 deletions lib/pullwr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "zebra.h"

#include <sys/ioctl.h>

#include "pullwr.h"
#include "memory.h"
#include "monotime.h"
Expand Down
1 change: 1 addition & 0 deletions lib/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ pkginclude_HEADERS += \
lib/frr_pthread.h \
lib/frratomic.h \
lib/frrcu.h \
lib/frrsendmmsg.h \
lib/frrstr.h \
lib/graph.h \
lib/hash.h \
Expand Down
1 change: 1 addition & 0 deletions lib/vrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <zebra.h>
#include <sys/ioctl.h>

#include "if.h"
#include "vrf.h"
Expand Down
59 changes: 0 additions & 59 deletions lib/zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <signal.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
#ifdef HAVE_STROPTS_H
#include <stropts.h>
#endif /* HAVE_STROPTS_H */
Expand All @@ -37,19 +36,14 @@
#include <sys/sysctl.h>
#endif
#endif /* HAVE_SYS_SYSCTL_H */
#include <sys/ioctl.h>
#ifdef HAVE_SYS_CONF_H
#include <sys/conf.h>
#endif /* HAVE_SYS_CONF_H */
#ifdef HAVE_SYS_KSYM_H
#include <sys/ksym.h>
#endif /* HAVE_SYS_KSYM_H */
#include <syslog.h>
#include <sys/time.h>
#include <time.h>
#include <sys/uio.h>
#include <sys/utsname.h>
#include <sys/resource.h>
#include <limits.h>
#include <inttypes.h>
#include <stdbool.h>
Expand All @@ -63,11 +57,6 @@
/* misc include group */
#include <stdarg.h>

#ifdef HAVE_LCAPS
#include <sys/capability.h>
#include <sys/prctl.h>
#endif /* HAVE_LCAPS */

/* network include group */

#include <sys/socket.h>
Expand All @@ -83,15 +72,9 @@
#endif
#endif

#ifdef CRYPTO_OPENSSL
#include <openssl/evp.h>
#include <openssl/hmac.h>
#endif

#include "openbsd-tree.h"

#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>

Expand Down Expand Up @@ -144,32 +127,10 @@
#include <netinet6/ip6.h>
#endif /* HAVE_NETINET6_IP6_H */

#include <netinet/icmp6.h>

#ifdef HAVE_NETINET6_ND6_H
#include <netinet6/nd6.h>
#endif /* HAVE_NETINET6_ND6_H */

/* Some systems do not define UINT32_MAX, etc.. from inttypes.h
* e.g. this makes life easier for FBSD 4.11 users.
*/
#ifndef INT16_MAX
#define INT16_MAX (32767)
#endif
#ifndef INT32_MAX
#define INT32_MAX (2147483647)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX (65535U)
#endif
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif

#ifdef HAVE_GLIBC_BACKTRACE
#include <execinfo.h>
#endif /* HAVE_GLIBC_BACKTRACE */

/* Local includes: */
#if !defined(__GNUC__)
#define __attribute__(x)
Expand Down Expand Up @@ -203,26 +164,6 @@ size_t strlcpy(char *__restrict dest,
void explicit_bzero(void *buf, size_t len);
#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.
* Here, we define those that are not present
Expand Down
4 changes: 4 additions & 0 deletions lib/zlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include "zebra.h"

#ifdef HAVE_GLIBC_BACKTRACE
#include <execinfo.h>
#endif /* HAVE_GLIBC_BACKTRACE */

#include <unistd.h>
#include <sys/time.h>
#include <sys/mman.h>
Expand Down
2 changes: 2 additions & 0 deletions lib/zlog_5424.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "zebra.h"

#include "frrsendmmsg.h"

#include "zlog_5424.h"

#include <sys/un.h>
Expand Down
2 changes: 2 additions & 0 deletions lib/zlog_live.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "zebra.h"

#include "frrsendmmsg.h"

#include "zlog_live.h"

#include "memory.h"
Expand Down
1 change: 1 addition & 0 deletions nhrpd/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <errno.h>
#include <linux/if_packet.h>
#include <sys/ioctl.h>

#include "nhrp_protocol.h"
#include "os.h"
Expand Down
6 changes: 6 additions & 0 deletions ospf6d/ospf6_auth_trailer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
*/

#include "zebra.h"

#ifdef CRYPTO_OPENSSL
#include <openssl/evp.h>
#include <openssl/hmac.h>
#endif

#include "config.h"
#include "memory.h"
#include "ospf6d.h"
Expand Down
5 changes: 5 additions & 0 deletions ospfd/ospf_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

#include <zebra.h>

#ifdef CRYPTO_OPENSSL
#include <openssl/evp.h>
#include <openssl/hmac.h>
#endif

#include "linklist.h"
#include "if.h"
#include "checksum.h"
Expand Down
Loading
Loading