From 72801d0fbf90fb4193d1592908b485f183ed85fb Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 10 Mar 2022 23:38:01 +0100 Subject: [PATCH] net: Make single-use macros local. A few macros are defined in net.h but are only used in a single C file. Move those to where they are used to make the code easier to follow. DCCP_SOCKOPT_RX_CCID is not used at all, so remove that. --- dccp_recv.c | 7 +++++++ dccp_send.c | 11 +++++++++++ net.c | 20 ++++++++++++++++++++ net.h | 41 ----------------------------------------- 4 files changed, 38 insertions(+), 41 deletions(-) diff --git a/dccp_recv.c b/dccp_recv.c index fe2f7abf..3e106636 100644 --- a/dccp_recv.c +++ b/dccp_recv.c @@ -27,6 +27,10 @@ #include "net.h" #include "fd.h" +#ifndef DCCP_SOCKOPT_CCID +#define DCCP_SOCKOPT_CCID 13 /**< Sets both TX/RX CCID. */ +#endif + static void dccp_recv_close(struct receiver_node *rn) { if (rn->fd > 0) @@ -59,6 +63,9 @@ static int dccp_recv_ccid_support_check(const struct lls_parse_result *lpr) return 1; } +/** Flowopt shortcut */ +#define OPT_ADD(fo, lev, opt, val, len) flowopt_add(fo, lev, opt, #opt, val, len) + static int dccp_recv_open(struct receiver_node *rn) { struct lls_parse_result *lpr = rn->lpr; diff --git a/dccp_send.c b/dccp_send.c index 15a361ba..6182c964 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -45,6 +45,10 @@ static void dccp_pre_monitor(struct sched *s) sched_monitor_readfd(dss->listen_fds[n], s); } +#ifndef DCCP_SOCKOPT_TX_CCID +#define DCCP_SOCKOPT_TX_CCID 14 /**< Set/get the TX CCID. */ +#endif + /** * Query the TX CCID used on the sender-client half connection. * \param sockfd Server socket descriptor to query (after accept(2)). @@ -89,6 +93,13 @@ static void dccp_shutdown(void) free_sender_status(dss); } +#ifndef DCCP_SOCKOPT_GET_CUR_MPS +#define DCCP_SOCKOPT_GET_CUR_MPS 5 /**< Max packet size, RFC 4340, 14. */ +#endif + +/** Estimated worst-case length of a DCCP header including options. */ +#define DCCP_MAX_HEADER 128 + /** * Obtain current MPS according to RFC 4340, sec. 14. */ static int dccp_init_fec(struct sender_client *sc) { diff --git a/net.c b/net.c index 4dd37674..23cd8032 100644 --- a/net.c +++ b/net.c @@ -224,6 +224,10 @@ const char *stringify_port(int port, const char *transport) return service; } +#ifndef SOCK_DCCP +#define SOCK_DCCP 6 /**< Linux socket type. */ +#endif + /** * Determine the socket type for a given layer-4 protocol. * @@ -834,6 +838,10 @@ int para_accept(int fd, void *addr, socklen_t size, int *new_fd) return -ERRNO_TO_PARA_ERROR(errno); } +#ifndef DCCP_SOCKOPT_AVAILABLE_CCIDS +#define DCCP_SOCKOPT_AVAILABLE_CCIDS 12 /**< List of supported CCIDs. */ +#endif + /** * Probe the list of DCCP CCIDs configured on this host. * \param ccid_array Pointer to return statically allocated array in. @@ -866,6 +874,18 @@ int dccp_available_ccids(uint8_t **ccid_array) return nccids; } +/** + * The buffer size of the sun_path component of struct sockaddr_un. + * + * While glibc doesn't define UNIX_PATH_MAX, it documents it has being limited + * to 108 bytes. On NetBSD it is only 104 bytes though. We trust UNIX_PATH_MAX + * if it is defined and use the size of the ->sun_path member otherwise. This + * should be safe everywhere. + */ +#ifndef UNIX_PATH_MAX +#define UNIX_PATH_MAX (sizeof(((struct sockaddr_un *)0)->sun_path)) +#endif + /* * Prepare a structure for AF_UNIX socket addresses. * diff --git a/net.h b/net.h index 9c06dd48..9b6591de 100644 --- a/net.h +++ b/net.h @@ -1,53 +1,16 @@ /* Copyright (C) 2006 Andre Noll , see file COPYING. */ /** \file net.h exported symbols from net.c */ -/** - * The buffer size of the sun_path component of struct sockaddr_un. - * - * While glibc doesn't define \p UNIX_PATH_MAX, it documents it has being - * limited to 108 bytes. On NetBSD it is only 104 bytes though. We trust \p - * UNIX_PATH_MAX if it is defined and use the size of the ->sun_path member - * otherwise. This should be safe everywhere. - */ -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX (sizeof(((struct sockaddr_un *)0)->sun_path)) -#endif - /* Userland defines for Linux DCCP support. */ #ifndef IPPROTO_DCCP #define IPPROTO_DCCP 33 /**< IANA assigned value. */ #endif -#ifndef SOCK_DCCP -#define SOCK_DCCP 6 /**< Linux socket type. */ -#endif - -#ifndef DCCP_SOCKOPT_RX_CCID -/** Per-connection CCID support (set/get the RX CCID, since v2.6.30-rc1). */ -#define DCCP_SOCKOPT_RX_CCID 15 -#endif - #ifndef SOL_DCCP #define SOL_DCCP 269 /**< Linux socket level. */ #endif -#ifndef DCCP_SOCKOPT_GET_CUR_MPS -#define DCCP_SOCKOPT_GET_CUR_MPS 5 /**< Max packet size, RFC 4340, 14. */ -#endif - -#ifndef DCCP_SOCKOPT_AVAILABLE_CCIDS -#define DCCP_SOCKOPT_AVAILABLE_CCIDS 12 /**< List of supported CCIDs. */ -#endif - -#ifndef DCCP_SOCKOPT_CCID -#define DCCP_SOCKOPT_CCID 13 /**< Sets both TX/RX CCID. */ -#endif - -#ifndef DCCP_SOCKOPT_TX_CCID -#define DCCP_SOCKOPT_TX_CCID 14 /**< Set/get the TX CCID. */ -#endif - /** The maximum length of the host component in an URL. */ #define MAX_HOSTLEN 256 @@ -58,8 +21,6 @@ struct flowopts *flowopt_new(void); void flowopt_add(struct flowopts *fo, int level, int opt, const char *name, const void *val, int len); void flowopt_cleanup(struct flowopts *fo); -/** Flowopt shortcut macros */ -#define OPT_ADD(fo, lev, opt, val, len) flowopt_add(fo, lev, opt, #opt, val, len) /** * Functions to parse and validate (parts of) URLs. @@ -150,8 +111,6 @@ ssize_t send_cred_buffer(int, char*); /** * Functions and definitions to support \p IPPROTO_DCCP */ -/** Estimated worst-case length of a DCCP header including options. */ -#define DCCP_MAX_HEADER 128 /** Hardcoded maximum number of separate CCID modules compiled into a host. */ #define DCCP_MAX_HOST_CCIDS 20 int dccp_available_ccids(uint8_t **ccid_array); -- 2.39.2