From 76e6067e13831569deca05dbb557d921998e3eb2 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Thu, 11 Jun 2020 23:08:45 +0200 Subject: Create a helper function to loop through different possible connections and convert proxy to use it --- utils.h | 101 ++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 41 deletions(-) (limited to 'utils.h') diff --git a/utils.h b/utils.h index 8f8a153..5a6f69e 100644 --- a/utils.h +++ b/utils.h @@ -10,6 +10,66 @@ struct list_head { struct list_head *prev; }; +#define zmalloc(s) __zmalloc(__func__, __LINE__, s) +void *__zmalloc(const char *fn, int line, size_t s); + +#define xstrdup(s) __xstrdup(__func__, __LINE__, s) +char *__xstrdup(const char *fn, int line, const char *s); + +#define xstrndup(s, n) __xstrndup(__func__, __LINE__, s, n) +char *__xstrndup(const char *fn, int line, const char *s, size_t n); + +#define xfree(s) __xfree(__func__, __LINE__, s) +void __xfree(const char *fn, int line, void *ptr); + +void debug_resource_usage(); + +#define ADDRSTRLEN (9 /*strlen("AF_INETX ")*/ + INET6_ADDRSTRLEN + 6 /*strlen(" 65535")*/ + 1) +struct sockaddr_in46 { + union { + struct sockaddr_storage storage; + struct sockaddr_in in4; + struct sockaddr_in6 in6; + }; + socklen_t addrlen; + struct list_head list; +}; + +struct connection { + struct sockaddr_in46 remote; + char remotestr[ADDRSTRLEN]; + + struct sockaddr_in46 local; + char localstr[ADDRSTRLEN]; + + struct list_head *addrs; + unsigned next_addr; + + void (*callback)(struct cfg *, struct connection *, int res); +}; + +struct uring_task; + +void socket_set_low_latency(struct cfg *cfg, int sfd); + +void connect_any(struct cfg *cfg, struct uring_task *task, + struct list_head *addrs, struct connection *conn, + void (*callback)(struct cfg *, struct connection *, int res)); + +uint16_t sockaddr_port(struct sockaddr_in46 *addr); + +char *sockaddr_to_str(struct sockaddr_in46 *addr, char *buf, size_t buflen); + +int strtou16_strict(const char *str, uint16_t *result); + +static inline bool empty_str(const char *str) +{ + if (!str || str[0] == '\0') + return true; + else + return false; +} + #define LIST_HEAD_INIT(name) { &(name), &(name) } #define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name) @@ -79,47 +139,6 @@ static inline bool list_empty(struct list_head *list) &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) -#define zmalloc(s) __zmalloc(__func__, __LINE__, s) -void *__zmalloc(const char *fn, int line, size_t s); - -#define xstrdup(s) __xstrdup(__func__, __LINE__, s) -char *__xstrdup(const char *fn, int line, const char *s); - -#define xstrndup(s, n) __xstrndup(__func__, __LINE__, s, n) -char *__xstrndup(const char *fn, int line, const char *s, size_t n); - -#define xfree(s) __xfree(__func__, __LINE__, s) -void __xfree(const char *fn, int line, void *ptr); - -void debug_resource_usage(); - -#define ADDRSTRLEN (9 /*strlen("AF_INETX ")*/ + INET6_ADDRSTRLEN + 6 /*strlen(" 65535")*/ + 1) -struct sockaddr_in46 { - union { - struct sockaddr_storage storage; - struct sockaddr_in in4; - struct sockaddr_in6 in6; - }; - socklen_t addrlen; - struct list_head list; -}; - -void socket_set_gaming_options(struct cfg *cfg, int sfd); - -uint16_t sockaddr_port(struct sockaddr_in46 *addr); - -char *sockaddr_to_str(struct sockaddr_in46 *addr, char *buf, size_t buflen); - -int strtou16_strict(const char *str, uint16_t *result); - -static inline bool empty_str(const char *str) -{ - if (!str || str[0] == '\0') - return true; - else - return false; -} - /* #define _cleanup_(x) __attribute__((cleanup(x))) -- cgit v1.2.3