From a12d0ffaefbee486dc1131ffe66531c9aa220766 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Thu, 2 Apr 2020 07:03:24 +0000 Subject: [PATCH 01/11] Commit of ForwrdingTableUtility (ftctl) brought over from the private repo. --- Makefile | 1 + src/glb-director/cli/main.c | 66 +---- src/glb-director/ftctl/Makefile | 50 ++++ src/glb-director/ftctl/glb-ftctl.h | 54 ++++ src/glb-director/ftctl/main.c | 405 ++++++++++++++++++++++++++++ src/glb-director/glb_config_types.h | 94 +++++++ src/glb-director/glb_consts.h | 79 ++++++ src/glb-director/glb_fwd_config.c | 7 +- src/glb-director/glb_fwd_config.h | 16 -- 9 files changed, 691 insertions(+), 81 deletions(-) create mode 100644 src/glb-director/ftctl/Makefile create mode 100644 src/glb-director/ftctl/glb-ftctl.h create mode 100644 src/glb-director/ftctl/main.c create mode 100644 src/glb-director/glb_config_types.h create mode 100644 src/glb-director/glb_consts.h diff --git a/Makefile b/Makefile index c94302a..0cf85c4 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,4 @@ clean: make -C src/glb-healthcheck clean make -C src/glb-director clean make -C src/glb-director/cli clean + make -C src/glb-director/ftctl clean diff --git a/src/glb-director/cli/main.c b/src/glb-director/cli/main.c index dea7079..e26a745 100644 --- a/src/glb-director/cli/main.c +++ b/src/glb-director/cli/main.c @@ -38,72 +38,14 @@ #include "log.h" -#define GLB_BACKEND_HEALTH_DOWN 0 -#define GLB_BACKEND_HEALTH_UP 1 +#include "glb_consts.h" +#include "glb_config_types.h" -#define GLB_BACKEND_STATE_FILLING 0 -#define GLB_BACKEND_STATE_ACTIVE 1 -#define GLB_BACKEND_STATE_DRAINING_INACTIVE 2 - -// http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml -#define GLB_FAMILY_RESERVED 0 -#define GLB_FAMILY_IPV4 1 -#define GLB_FAMILY_IPV6 2 - -#define GLB_IPPROTO_UDP 17 -#define GLB_IPPROTO_TCP 6 int siphash(uint8_t *out, const uint8_t *in, uint64_t inlen, const uint8_t *k); #pragma pack(1) -typedef struct { - uint32_t file_fmt_ver; - uint32_t num_tables; - uint32_t table_entries; - uint32_t max_num_backends; - uint32_t max_num_binds; -} bin_file_header; - -typedef struct { - uint32_t inet_family; - - union { - char v6[16]; - struct { - uint32_t v4; - char reserved[12]; - }; - } ip; - - uint16_t state; - uint16_t health; -} backend_entry; - -typedef struct { - uint32_t inet_family; - - union { - char v6[16]; - struct { - uint32_t v4; - char _[12]; - }; - } ip; - - uint16_t ip_bits; - - uint16_t port_start; - uint16_t port_end; - uint8_t ipproto; - uint8_t reserved; -} bind_entry; - -typedef struct { - uint32_t primary_idx; - uint32_t secondary_idx; -} table_entry; - typedef struct { uint32_t index; uint64_t hash; @@ -404,9 +346,9 @@ int main(int argc, char *argv[]) free(bind_ip); if (!strcmp(bind_proto, "tcp")) { - entry.ipproto = GLB_IPPROTO_TCP; + entry.ipproto = IPPROTO_TCP; } else if (!strcmp(bind_proto, "udp")) { - entry.ipproto = GLB_IPPROTO_UDP; + entry.ipproto = IPPROTO_UDP; } else { glb_log_error_and_exit("Bad protocol!"); } diff --git a/src/glb-director/ftctl/Makefile b/src/glb-director/ftctl/Makefile new file mode 100644 index 0000000..2b988b1 --- /dev/null +++ b/src/glb-director/ftctl/Makefile @@ -0,0 +1,50 @@ +# BSD 3-Clause License +# +# Copyright (c) 2019 Roblox Corporation. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +## Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +## Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +## Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +all: glb-ftctl + +FTCTL_SRCS = main.c +WERROR_FLAGS += -Werror + +CFLAGS += -O3 -g -Wall $(WERROR_FLAGS) + +APP = glb-ftctl + +glb-ftctl: $(FTCTL_SRCS) + gcc \ + $(FTCTL_SRCS) \ + $(CFLAGS) \ + -I`pwd`/..\ + -I`pwd`/../../glb-redirect/ \ + -o glb-ftctl + + +clean: + rm -Rf glb-ftctl diff --git a/src/glb-director/ftctl/glb-ftctl.h b/src/glb-director/ftctl/glb-ftctl.h new file mode 100644 index 0000000..49500c1 --- /dev/null +++ b/src/glb-director/ftctl/glb-ftctl.h @@ -0,0 +1,54 @@ +/* + * BSD 3-Clause License + * + * Copyright (c) 2019 Roblox Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +52 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __GLB_FTCTL_H__ +#define __GLB_FTCTL_H__ + +#define FTCTL_TABLE_ENTRIES_ALL ((uint32_t)~0) +#define FTCTL_CHECK_IF_ENTRIES_ALL (x) ((x) == FTCTL_TABLE_ENTRIES_ALL) +#define FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(x, y) \ + (((x) == FTCTL_TABLE_ENTRIES_ALL) || ((x) == y)) + + +typedef struct ftctl_config_ { + boolean detailed; /* d: print everything other than table-entries */ + uint32_t table_num; /* n: print only the entries for table_num */ + + boolean verbose; /* v: print everything */ +} ftctl_config_t; + +#endif +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/src/glb-director/ftctl/main.c b/src/glb-director/ftctl/main.c new file mode 100644 index 0000000..c25bb8e --- /dev/null +++ b/src/glb-director/ftctl/main.c @@ -0,0 +1,405 @@ +/* + * BSD 3-Clause License + * + * Copyright (c) 2019 Roblox Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include +#include "glb-includes/glb_common_includes.h" +#include "../glb_consts.h" +#include "glb_config_types.h" +#include "glb-ftctl.h" + +ftctl_config_t cli_config; + +/* + * This file contains code for a utility to dump the contents of a binary + * forwarding table (BFT) used by GLB-director. + * + * In the future, the displayed items can be displayed in more fancy ways. + * This is just a start. + */ + +/* + * glb_ftctl_usage() + * + */ +void glb_ftctl_usage() +{ + printf("Usage: glb-director-ftctl \n" \ + " Options: \n" \ + " -d, --detail Print everything other than table-entries\n" \ + " -n, --table-num Print forwarding-table entries only for " \ + "this table (numbering starts with 0)\n" \ + " -v, --verbose Print everything\n" \ + "\n" \ + " Default behavior: Print only the common info\n\n" \ + ); +} + +/* + * fread_ret_check() + * + * Function to check if the returned count by a call to fread() can be + * considered proper. + * + */ + +static int +glb_fread_ret_check(size_t ret, size_t num_expect_to_read, + boolean check_num_expect) +{ + /* Improper read */ + if (check_num_expect) { + if (ret < num_expect_to_read) { + return 0; + } + } else { + if (!ret) { + return 0; + } + } + + /* Proper read */ + return 1; +} + +/* + * glb_ip_addr_to_str() + * + * Converts an IP address (v4 or v6) to a corresponding string representation, + * based on the inet_family provided. + * + * Caller's responsibility to ensure that dst can hold an appropriate length of + * characters. + */ + +static boolean +glb_ip_addr_to_str(uint32_t glb_inet_family, const void *src, char *dst) +{ + socklen_t size = 0; + uint32_t inet_family = inet_family; + + if (glb_inet_family == GLB_FAMILY_IPV4) { + inet_family = AF_INET; + size = INET_ADDRSTRLEN; + } else if (glb_inet_family == GLB_FAMILY_IPV6) { + inet_family = AF_INET6; + size = INET6_ADDRSTRLEN; + } else { + return FALSE; + } + + inet_ntop(inet_family, src, dst, size); + return TRUE; +} + +/* + * glb_read_per_table_fields() + * + * Prints ther per-table fields. + * Assumption is that the read-offet for "in" is at the appropriate offset for + * a table that is sought to be read. + * + */ +static int +glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, + uint32_t table_num) +{ + uint32_t i = 0; + uint32_t num_backends; + + backend_entry *backendp; + bind_entry *bindp; + table_entry *tablep; + + uint32_t num_binds; + char hash_key[16]; + char ip[INET_ADDRSTRLEN]; + size_t ret; + + /* Read the # of backends that this BFT file knows about */ + ret = fread(&num_backends, sizeof(uint32_t), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + /* Deal with backends : read each backend & display same */ + backendp = (backend_entry *) malloc(bfh->max_num_backends * \ + sizeof(backend_entry)); + if (!backendp) { + return -1; + } + ret = fread(backendp, sizeof(backend_entry), bfh->max_num_backends, in); + if (!glb_fread_ret_check(ret, bfh->max_num_backends, FALSE)) { + return -1; + } + + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, + table_num)) { + printf("\n\n*** Table #: %d ***", table_num); + printf("\n\nBackends:"); + for (i = 0; i < num_backends; i++) { + if (glb_ip_addr_to_str(backendp[i].inet_family, &backendp[i].ip, + ip)) { + printf("\n%u: \t%s \t: %s, \t%s, \t%s", + i, ip, glb_addr_family_names[backendp[i].inet_family], + glb_state_names[backendp[i].state], + glb_backend_health_status[backendp[i].health]); + } + } + } + + + + /* Number of binds */ + ret = fread(&num_binds, sizeof(uint32_t), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + /* Deal with binds: read & display each bind entry */ + bindp = (bind_entry *)malloc(bfh->max_num_binds * sizeof(bind_entry)); + if (!bindp) { + return -1; + } + + ret = fread(bindp, sizeof(bind_entry), bfh->max_num_binds, in); + if (!glb_fread_ret_check(ret, bfh->max_num_binds, TRUE)) { + free(bindp); + return -1; + } + + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, + table_num)) { + printf("\n\nBinds:"); + + for (i = 0; i < num_binds; i++) { + struct protoent *proto; + + if (glb_ip_addr_to_str(bindp[i].inet_family, &bindp[i].ip, ip)) { + proto = getprotobynumber(bindp[i].ipproto); + printf("\n%40s, %s, Port: %u-%u", + ip, + (proto ? proto->p_name : "Unknown"), + bindp[i].port_start, + bindp[i].port_end); + } + } + } + + free(bindp); + + /* Hash key */ + ret = fread(hash_key, 16, 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, + table_num)) { + printf("\n\nHash-key: 0x"); + for (i = 0; i < 16; i++) { + printf("%x", (unsigned char)hash_key[i]); + } + printf("\n"); + } + /* Deal with the rendezvous hash-table */ + tablep = (table_entry *)malloc(sizeof(table_entry)); + if (!tablep) { + return -1; + } + + for (i = 0; i < bfh->table_entries; i++) { + ret = fread(&tablep->primary_idx, sizeof(uint32_t), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + free(tablep); + return -1; + } + ret = fread(&tablep->secondary_idx, sizeof(uint32_t), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + free(tablep); + return -1; + } + if (cli_config.verbose && \ + FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, + table_num)) { + if (i ==0) { + printf("\n\nForwarding table:"); + } + printf("\nEntry: 0x%x", i); + printf(" %4d", tablep->primary_idx); + printf(" %4d", tablep->secondary_idx); + } + } + free(tablep); + free(backendp); + return 0; +} + +/* + * glb_print_bin_file_header() + * + * Print the contents of the file header + */ +static void +glb_print_bin_file_header(bin_file_header *bfh) +{ + printf("\nFile header"); + printf("\n\tVersion: %u", bfh->file_fmt_ver); + printf("\n\tNumber of tables: %u", bfh->num_tables); + printf("\n\tTable entries: %u", bfh->table_entries); + printf("\n\tMax. # of backends: %u", bfh->max_num_backends); + printf("\n\tMax. # of binds: %u\n", bfh->max_num_binds); +} + +static struct option longopts[] = { + { "detail", no_argument, NULL, 'd' }, + { "num-table", required_argument, NULL, 'n' }, + { "verbose", no_argument, NULL, 'v' }, + { "help", no_argument, NULL, 'h' }, + { NULL, 0, NULL, 0 } +}; + +/* + * Parse the args & determine validity + * + * -d, --detail Print everything other than table-entries + * -n, --num-table Print entries only from table-number specified + * -v, --verbose Print everything + * -h, --help Help + * + * Default behavior: Print only the table-names, VIPs, backends + */ +static int +parse_args(int argc, char **argv, const char **src_binary) +{ + int c; + + cli_config.table_num = FTCTL_TABLE_ENTRIES_ALL; + + while ((c = getopt_long(argc, argv, "n:dvh?", longopts, + NULL)) != -1) { + switch(c) { + case 'd': + cli_config.detailed = TRUE; + break; + + case 'n': + cli_config.table_num = atoi(optarg); + break; + + case 'v': + cli_config.verbose = TRUE; + break; + + case 'h': + case '?': + default: + return(-1); + } + } + + if (optind == argc) { + return(-1); + } + if (cli_config.detailed && cli_config.verbose) { + printf("Mutually exclusive options configured together\n"); + return(-1); + } + *src_binary = argv[optind]; + return(0); +} + + +int +main(int argc, char **argv) +{ + char buffer[256]; + uint32_t i = 0; + bin_file_header *bfh; + size_t ret; + const char *src_binary; + + if (parse_args(argc, argv, &src_binary)) { + glb_ftctl_usage(); + return -1; + } + + + /* Open the binary forwarding table file for reading */ + FILE *in = fopen(src_binary, "rb"); + if (in == NULL) { + printf("Could not open forwarding table file for reading: %s", + src_binary); + return -1; + } + + /* Read magic word */ + ret = fread(buffer, 4, 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + /* Read file header */ + bfh = malloc(sizeof(bin_file_header)); + if (!bfh) { + return -1; + } + ret = fread(bfh, sizeof(bin_file_header), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + /* Print the header */ + glb_print_bin_file_header(bfh); + + printf("\nNumber of tables: %u", bfh->num_tables); + + if (cli_config.detailed || cli_config.verbose) { + /* For each table, read the fields & display same */ + for (i = 0; i < bfh->num_tables; i++) { + ret = glb_read_per_table_fields(in, bfh, i); + } + } + + free(bfh); + printf("\n"); + return(ret); +} +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/src/glb-director/glb_config_types.h b/src/glb-director/glb_config_types.h new file mode 100644 index 0000000..d8d4c72 --- /dev/null +++ b/src/glb-director/glb_config_types.h @@ -0,0 +1,94 @@ +/* + * BSD 3-Clause License + * + * Copyright (c) 2019 Roblox Corporation. + * Copyright (c) 2018 GitHub. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __GLB_CONFIG_TYPES_H__ + +#define __GLB_CONFIG_TYPES_H__ + +typedef enum {FALSE, TRUE} boolean; + +typedef struct { + uint32_t file_fmt_ver; + uint32_t num_tables; + uint32_t table_entries; + uint32_t max_num_backends; + uint32_t max_num_binds; +} bin_file_header; + +typedef struct { + uint32_t inet_family; + + union { + char v6[16]; + struct { + uint32_t v4; + char reserved[12]; + }; + } ip; + + uint16_t state; + uint16_t health; +} backend_entry; + +typedef struct { + uint32_t inet_family; + + union { + char v6[16]; + struct { + uint32_t v4; + char _[12]; + }; + } ip; + + uint16_t ip_bits; + + uint16_t port_start; + uint16_t port_end; + uint8_t ipproto; + uint8_t reserved; +} bind_entry; + +struct table_entry_ { + uint32_t primary_idx; + uint32_t secondary_idx; +} __attribute__((__packed__)); +typedef struct table_entry_ table_entry; + + +#endif /* __GLB_CONFIG_TYPES_H__ */ +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/src/glb-director/glb_consts.h b/src/glb-director/glb_consts.h new file mode 100644 index 0000000..7928e79 --- /dev/null +++ b/src/glb-director/glb_consts.h @@ -0,0 +1,79 @@ +/* + * BSD 3-Clause License + * + * Copyright (c) 2019 Roblox Corporation. + * Copyright (c) 2018 GitHub. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __GLB_CONSTS_H__ + +#define __GLB_CONSTS_H__ + +#define FILE_FORMAT_VERSION 2 +#define MAX_TABLE_ENTRIES 0x10000 +#define MAX_NUM_BACKENDS 0x100 +#define MAX_NUM_BINDS 0x100 + +// http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml + +typedef enum { + GLB_FAMILY_RESERVED = 0, + GLB_FAMILY_IPV4 = 1, + GLB_FAMILY_IPV6 = 2, + GLB_FAMILY_MAX +} glb_config_addr_family; + +const char *glb_addr_family_names[GLB_FAMILY_MAX] = \ + {"", "IPv4", "IPv6"}; + +typedef enum { + GLB_BACKEND_STATE_FILLING = 0, + GLB_BACKEND_STATE_ACTIVE = 1, + GLB_BACKEND_STATE_DRAINING_INACTIVE = 2, + GLB_BACKEND_STATE_MAX +} glb_config_host_state; + +const char *glb_state_names[GLB_BACKEND_STATE_MAX] = \ + {"Filling", "Active", "Draining_Inactive",}; + +typedef enum { + GLB_BACKEND_HEALTH_DOWN = 0, + GLB_BACKEND_HEALTH_UP = 1, + GLB_BACKEND_HEALTH_MAX = 2 +} glb_config_host_health; + +const char *glb_backend_health_status[GLB_BACKEND_HEALTH_MAX] = \ + {"UnHealthy", "Healthy"}; + +#endif /* __GLB_CONSTS_H__ */ +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/src/glb-director/glb_fwd_config.c b/src/glb-director/glb_fwd_config.c index 67f3c89..537ab61 100644 --- a/src/glb-director/glb_fwd_config.c +++ b/src/glb-director/glb_fwd_config.c @@ -52,6 +52,7 @@ #endif #include "config.h" +#include "glb_consts.h" #include "glb_fwd_config.h" #include "log.h" @@ -362,11 +363,11 @@ int check_config(struct glb_fwd_config_ctx *ctx) int supported_proto(int proto_num) { switch (proto_num) { - case SUPPORTED_PROTOS_ICMP: + case IPPROTO_ICMP: return 0; - case SUPPORTED_PROTOS_TCP: + case IPPROTO_TCP: return 0; - case SUPPORTED_PROTOS_UDP: + case IPPROTO_UDP: return 0; default: return 1; diff --git a/src/glb-director/glb_fwd_config.h b/src/glb-director/glb_fwd_config.h index de1bc5f..72830b7 100644 --- a/src/glb-director/glb_fwd_config.h +++ b/src/glb-director/glb_fwd_config.h @@ -42,22 +42,6 @@ #define FAMILY_IPV4 1 #define FAMILY_IPV6 2 -/* we only support icmp, tcp, udp */ -#define SUPPORTED_PROTOS_ICMP 1 -#define SUPPORTED_PROTOS_TCP 6 -#define SUPPORTED_PROTOS_UDP 17 - -typedef enum { - GLB_BACKEND_STATE_FILLING = 0, - GLB_BACKEND_STATE_ACTIVE = 1, - GLB_BACKEND_STATE_DRAINING = 2, -} glb_fwd_config_host_state; - -typedef enum { - GLB_BACKEND_HEALTH_DOWN = 0, - GLB_BACKEND_HEALTH_UP = 1, -} glb_fwd_config_host_health; - struct glb_fwd_config_content_table_backend { uint32_t family; union { From 9d64191c55a2041a357bab5fca20a802c86a281b Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Sat, 4 Apr 2020 05:59:00 +0000 Subject: [PATCH 02/11] Fixing the Vagrantfile to ensure that the directors startup fine: the CLI is a dependency for the glb-director package to install proper. --- Vagrantfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Vagrantfile b/Vagrantfile index a4ff68a..6afcf68 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -134,6 +134,7 @@ Vagrant.configure("2") do |config| dpdk-devbind --bind=igb_uio eth1 dpdk-devbind --status + apt install /vagrant/tmp/build/glb-director-cli*.deb apt install /vagrant/tmp/build/glb-director_*.deb apt install /vagrant/tmp/build/glb-healthcheck_*.deb From 17c416636713b98f44ff4f20eb6cbc80d74c3250 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Sat, 4 Apr 2020 19:56:41 +0000 Subject: [PATCH 03/11] 1. Code for generating ftctl as part of the .deb was missed out in the merge. 2. Corrected usage message. --- src/glb-director/ftctl/main.c | 4 ++-- src/glb-director/script/create-packages | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/glb-director/ftctl/main.c b/src/glb-director/ftctl/main.c index c25bb8e..b377dc3 100644 --- a/src/glb-director/ftctl/main.c +++ b/src/glb-director/ftctl/main.c @@ -56,10 +56,10 @@ ftctl_config_t cli_config; */ void glb_ftctl_usage() { - printf("Usage: glb-director-ftctl \n" \ + printf("Usage: glb-ftctl \n" \ " Options: \n" \ " -d, --detail Print everything other than table-entries\n" \ - " -n, --table-num Print forwarding-table entries only for " \ + " -n, --table-num Print information only for " \ "this table (numbering starts with 0)\n" \ " -v, --verbose Print everything\n" \ "\n" \ diff --git a/src/glb-director/script/create-packages b/src/glb-director/script/create-packages index b3811ef..6462276 100755 --- a/src/glb-director/script/create-packages +++ b/src/glb-director/script/create-packages @@ -38,9 +38,11 @@ cd $ROOTDIR make clean make -C cli clean +make -C ftctl clean make make -C cli +make -C ftctl ./cli/glb-director-cli build-config packaging/forwarding_table.json packaging/forwarding_table.bin @@ -51,7 +53,9 @@ fpm -f -s dir -t deb \ --license 'BSD 3-Clause' \ --maintainer 'GitHub ' \ cli/glb-director-cli=/usr/sbin/ \ - cli/glb-config-check=/usr/sbin/ + cli/glb-config-check=/usr/sbin/ \ + ftctl/glb-ftctl=/usr/sbin/ + fpm -f -s dir -t deb \ -n glb-director \ @@ -76,3 +80,4 @@ fi make clean make -C cli clean +make -C ftctl clean From 97c4ef21daf4aa263fdd833cc806d17fcef00dc3 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Sat, 4 Apr 2020 22:00:42 +0000 Subject: [PATCH 04/11] Fixing white-spaces. --- src/glb-director/ftctl/main.c | 58 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/glb-director/ftctl/main.c b/src/glb-director/ftctl/main.c index b377dc3..c193796 100644 --- a/src/glb-director/ftctl/main.c +++ b/src/glb-director/ftctl/main.c @@ -59,8 +59,8 @@ void glb_ftctl_usage() printf("Usage: glb-ftctl \n" \ " Options: \n" \ " -d, --detail Print everything other than table-entries\n" \ - " -n, --table-num Print information only for " \ - "this table (numbering starts with 0)\n" \ + " -n, --table-num Print information only for " \ + "this table (numbering starts with 0)\n" \ " -v, --verbose Print everything\n" \ "\n" \ " Default behavior: Print only the common info\n\n" \ @@ -68,7 +68,7 @@ void glb_ftctl_usage() } /* - * fread_ret_check() + * glb_fread_ret_check() * * Function to check if the returned count by a call to fread() can be * considered proper. @@ -89,7 +89,7 @@ glb_fread_ret_check(size_t ret, size_t num_expect_to_read, return 0; } } - + /* Proper read */ return 1; } @@ -142,12 +142,12 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, backend_entry *backendp; bind_entry *bindp; table_entry *tablep; - + uint32_t num_binds; char hash_key[16]; char ip[INET_ADDRSTRLEN]; size_t ret; - + /* Read the # of backends that this BFT file knows about */ ret = fread(&num_backends, sizeof(uint32_t), 1, in); if (!glb_fread_ret_check(ret, 1, TRUE)) { @@ -156,7 +156,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, /* Deal with backends : read each backend & display same */ backendp = (backend_entry *) malloc(bfh->max_num_backends * \ - sizeof(backend_entry)); + sizeof(backend_entry)); if (!backendp) { return -1; } @@ -164,7 +164,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, if (!glb_fread_ret_check(ret, bfh->max_num_backends, FALSE)) { return -1; } - + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\n*** Table #: %d ***", table_num); @@ -179,15 +179,13 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, } } } - - /* Number of binds */ ret = fread(&num_binds, sizeof(uint32_t), 1, in); if (!glb_fread_ret_check(ret, 1, TRUE)) { return -1; } - + /* Deal with binds: read & display each bind entry */ bindp = (bind_entry *)malloc(bfh->max_num_binds * sizeof(bind_entry)); if (!bindp) { @@ -203,7 +201,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\nBinds:"); - + for (i = 0; i < num_binds; i++) { struct protoent *proto; @@ -217,15 +215,15 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, } } } - + free(bindp); - + /* Hash key */ ret = fread(hash_key, 16, 1, in); if (!glb_fread_ret_check(ret, 1, TRUE)) { return -1; } - + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\nHash-key: 0x"); @@ -239,7 +237,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, if (!tablep) { return -1; } - + for (i = 0; i < bfh->table_entries; i++) { ret = fread(&tablep->primary_idx, sizeof(uint32_t), 1, in); if (!glb_fread_ret_check(ret, 1, TRUE)) { @@ -283,13 +281,14 @@ glb_print_bin_file_header(bin_file_header *bfh) printf("\n\tMax. # of binds: %u\n", bfh->max_num_binds); } -static struct option longopts[] = { - { "detail", no_argument, NULL, 'd' }, - { "num-table", required_argument, NULL, 'n' }, - { "verbose", no_argument, NULL, 'v' }, - { "help", no_argument, NULL, 'h' }, - { NULL, 0, NULL, 0 } -}; +static struct option longopts[] = \ + { + {"detail", no_argument, NULL, 'd'}, + {"num-table", required_argument, NULL, 'n'}, + {"verbose", no_argument, NULL, 'v'}, + { "help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; /* * Parse the args & determine validity @@ -305,9 +304,9 @@ static int parse_args(int argc, char **argv, const char **src_binary) { int c; - + cli_config.table_num = FTCTL_TABLE_ENTRIES_ALL; - + while ((c = getopt_long(argc, argv, "n:dvh?", longopts, NULL)) != -1) { switch(c) { @@ -318,7 +317,7 @@ parse_args(int argc, char **argv, const char **src_binary) case 'n': cli_config.table_num = atoi(optarg); break; - + case 'v': cli_config.verbose = TRUE; break; @@ -356,7 +355,6 @@ main(int argc, char **argv) return -1; } - /* Open the binary forwarding table file for reading */ FILE *in = fopen(src_binary, "rb"); if (in == NULL) { @@ -380,12 +378,12 @@ main(int argc, char **argv) if (!glb_fread_ret_check(ret, 1, TRUE)) { return -1; } - + /* Print the header */ glb_print_bin_file_header(bfh); - + printf("\nNumber of tables: %u", bfh->num_tables); - + if (cli_config.detailed || cli_config.verbose) { /* For each table, read the fields & display same */ for (i = 0; i < bfh->num_tables; i++) { From 0df448921a66ba9c8a5a032340d1817d4eadd530 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Sat, 4 Apr 2020 22:03:57 +0000 Subject: [PATCH 05/11] More whitespaces fixed. --- src/glb-director/ftctl/main.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/glb-director/ftctl/main.c b/src/glb-director/ftctl/main.c index c193796..2566d9b 100644 --- a/src/glb-director/ftctl/main.c +++ b/src/glb-director/ftctl/main.c @@ -165,8 +165,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, return -1; } - if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, - table_num)) { + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\n*** Table #: %d ***", table_num); printf("\n\nBackends:"); for (i = 0; i < num_backends; i++) { @@ -198,8 +197,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, return -1; } - if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, - table_num)) { + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\nBinds:"); for (i = 0; i < num_binds; i++) { @@ -224,8 +222,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, return -1; } - if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, - table_num)) { + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\nHash-key: 0x"); for (i = 0; i < 16; i++) { printf("%x", (unsigned char)hash_key[i]); From 40dddd5bab0027a8ff7bc1b3045139408bb08f0c Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Thu, 2 Apr 2020 07:03:24 +0000 Subject: [PATCH 06/11] Commit of ForwrdingTableUtility (ftctl) brought over from the private repo. --- Makefile | 1 + src/glb-director/cli/main.c | 66 +---- src/glb-director/ftctl/Makefile | 50 ++++ src/glb-director/ftctl/glb-ftctl.h | 54 ++++ src/glb-director/ftctl/main.c | 405 ++++++++++++++++++++++++++++ src/glb-director/glb_config_types.h | 94 +++++++ src/glb-director/glb_consts.h | 79 ++++++ src/glb-director/glb_fwd_config.c | 7 +- src/glb-director/glb_fwd_config.h | 16 -- 9 files changed, 691 insertions(+), 81 deletions(-) create mode 100644 src/glb-director/ftctl/Makefile create mode 100644 src/glb-director/ftctl/glb-ftctl.h create mode 100644 src/glb-director/ftctl/main.c create mode 100644 src/glb-director/glb_config_types.h create mode 100644 src/glb-director/glb_consts.h diff --git a/Makefile b/Makefile index c94302a..0cf85c4 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,4 @@ clean: make -C src/glb-healthcheck clean make -C src/glb-director clean make -C src/glb-director/cli clean + make -C src/glb-director/ftctl clean diff --git a/src/glb-director/cli/main.c b/src/glb-director/cli/main.c index dea7079..e26a745 100644 --- a/src/glb-director/cli/main.c +++ b/src/glb-director/cli/main.c @@ -38,72 +38,14 @@ #include "log.h" -#define GLB_BACKEND_HEALTH_DOWN 0 -#define GLB_BACKEND_HEALTH_UP 1 +#include "glb_consts.h" +#include "glb_config_types.h" -#define GLB_BACKEND_STATE_FILLING 0 -#define GLB_BACKEND_STATE_ACTIVE 1 -#define GLB_BACKEND_STATE_DRAINING_INACTIVE 2 - -// http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml -#define GLB_FAMILY_RESERVED 0 -#define GLB_FAMILY_IPV4 1 -#define GLB_FAMILY_IPV6 2 - -#define GLB_IPPROTO_UDP 17 -#define GLB_IPPROTO_TCP 6 int siphash(uint8_t *out, const uint8_t *in, uint64_t inlen, const uint8_t *k); #pragma pack(1) -typedef struct { - uint32_t file_fmt_ver; - uint32_t num_tables; - uint32_t table_entries; - uint32_t max_num_backends; - uint32_t max_num_binds; -} bin_file_header; - -typedef struct { - uint32_t inet_family; - - union { - char v6[16]; - struct { - uint32_t v4; - char reserved[12]; - }; - } ip; - - uint16_t state; - uint16_t health; -} backend_entry; - -typedef struct { - uint32_t inet_family; - - union { - char v6[16]; - struct { - uint32_t v4; - char _[12]; - }; - } ip; - - uint16_t ip_bits; - - uint16_t port_start; - uint16_t port_end; - uint8_t ipproto; - uint8_t reserved; -} bind_entry; - -typedef struct { - uint32_t primary_idx; - uint32_t secondary_idx; -} table_entry; - typedef struct { uint32_t index; uint64_t hash; @@ -404,9 +346,9 @@ int main(int argc, char *argv[]) free(bind_ip); if (!strcmp(bind_proto, "tcp")) { - entry.ipproto = GLB_IPPROTO_TCP; + entry.ipproto = IPPROTO_TCP; } else if (!strcmp(bind_proto, "udp")) { - entry.ipproto = GLB_IPPROTO_UDP; + entry.ipproto = IPPROTO_UDP; } else { glb_log_error_and_exit("Bad protocol!"); } diff --git a/src/glb-director/ftctl/Makefile b/src/glb-director/ftctl/Makefile new file mode 100644 index 0000000..2b988b1 --- /dev/null +++ b/src/glb-director/ftctl/Makefile @@ -0,0 +1,50 @@ +# BSD 3-Clause License +# +# Copyright (c) 2019 Roblox Corporation. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +## Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +## Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +## Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +all: glb-ftctl + +FTCTL_SRCS = main.c +WERROR_FLAGS += -Werror + +CFLAGS += -O3 -g -Wall $(WERROR_FLAGS) + +APP = glb-ftctl + +glb-ftctl: $(FTCTL_SRCS) + gcc \ + $(FTCTL_SRCS) \ + $(CFLAGS) \ + -I`pwd`/..\ + -I`pwd`/../../glb-redirect/ \ + -o glb-ftctl + + +clean: + rm -Rf glb-ftctl diff --git a/src/glb-director/ftctl/glb-ftctl.h b/src/glb-director/ftctl/glb-ftctl.h new file mode 100644 index 0000000..49500c1 --- /dev/null +++ b/src/glb-director/ftctl/glb-ftctl.h @@ -0,0 +1,54 @@ +/* + * BSD 3-Clause License + * + * Copyright (c) 2019 Roblox Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +52 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __GLB_FTCTL_H__ +#define __GLB_FTCTL_H__ + +#define FTCTL_TABLE_ENTRIES_ALL ((uint32_t)~0) +#define FTCTL_CHECK_IF_ENTRIES_ALL (x) ((x) == FTCTL_TABLE_ENTRIES_ALL) +#define FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(x, y) \ + (((x) == FTCTL_TABLE_ENTRIES_ALL) || ((x) == y)) + + +typedef struct ftctl_config_ { + boolean detailed; /* d: print everything other than table-entries */ + uint32_t table_num; /* n: print only the entries for table_num */ + + boolean verbose; /* v: print everything */ +} ftctl_config_t; + +#endif +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/src/glb-director/ftctl/main.c b/src/glb-director/ftctl/main.c new file mode 100644 index 0000000..c25bb8e --- /dev/null +++ b/src/glb-director/ftctl/main.c @@ -0,0 +1,405 @@ +/* + * BSD 3-Clause License + * + * Copyright (c) 2019 Roblox Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include +#include "glb-includes/glb_common_includes.h" +#include "../glb_consts.h" +#include "glb_config_types.h" +#include "glb-ftctl.h" + +ftctl_config_t cli_config; + +/* + * This file contains code for a utility to dump the contents of a binary + * forwarding table (BFT) used by GLB-director. + * + * In the future, the displayed items can be displayed in more fancy ways. + * This is just a start. + */ + +/* + * glb_ftctl_usage() + * + */ +void glb_ftctl_usage() +{ + printf("Usage: glb-director-ftctl \n" \ + " Options: \n" \ + " -d, --detail Print everything other than table-entries\n" \ + " -n, --table-num Print forwarding-table entries only for " \ + "this table (numbering starts with 0)\n" \ + " -v, --verbose Print everything\n" \ + "\n" \ + " Default behavior: Print only the common info\n\n" \ + ); +} + +/* + * fread_ret_check() + * + * Function to check if the returned count by a call to fread() can be + * considered proper. + * + */ + +static int +glb_fread_ret_check(size_t ret, size_t num_expect_to_read, + boolean check_num_expect) +{ + /* Improper read */ + if (check_num_expect) { + if (ret < num_expect_to_read) { + return 0; + } + } else { + if (!ret) { + return 0; + } + } + + /* Proper read */ + return 1; +} + +/* + * glb_ip_addr_to_str() + * + * Converts an IP address (v4 or v6) to a corresponding string representation, + * based on the inet_family provided. + * + * Caller's responsibility to ensure that dst can hold an appropriate length of + * characters. + */ + +static boolean +glb_ip_addr_to_str(uint32_t glb_inet_family, const void *src, char *dst) +{ + socklen_t size = 0; + uint32_t inet_family = inet_family; + + if (glb_inet_family == GLB_FAMILY_IPV4) { + inet_family = AF_INET; + size = INET_ADDRSTRLEN; + } else if (glb_inet_family == GLB_FAMILY_IPV6) { + inet_family = AF_INET6; + size = INET6_ADDRSTRLEN; + } else { + return FALSE; + } + + inet_ntop(inet_family, src, dst, size); + return TRUE; +} + +/* + * glb_read_per_table_fields() + * + * Prints ther per-table fields. + * Assumption is that the read-offet for "in" is at the appropriate offset for + * a table that is sought to be read. + * + */ +static int +glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, + uint32_t table_num) +{ + uint32_t i = 0; + uint32_t num_backends; + + backend_entry *backendp; + bind_entry *bindp; + table_entry *tablep; + + uint32_t num_binds; + char hash_key[16]; + char ip[INET_ADDRSTRLEN]; + size_t ret; + + /* Read the # of backends that this BFT file knows about */ + ret = fread(&num_backends, sizeof(uint32_t), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + /* Deal with backends : read each backend & display same */ + backendp = (backend_entry *) malloc(bfh->max_num_backends * \ + sizeof(backend_entry)); + if (!backendp) { + return -1; + } + ret = fread(backendp, sizeof(backend_entry), bfh->max_num_backends, in); + if (!glb_fread_ret_check(ret, bfh->max_num_backends, FALSE)) { + return -1; + } + + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, + table_num)) { + printf("\n\n*** Table #: %d ***", table_num); + printf("\n\nBackends:"); + for (i = 0; i < num_backends; i++) { + if (glb_ip_addr_to_str(backendp[i].inet_family, &backendp[i].ip, + ip)) { + printf("\n%u: \t%s \t: %s, \t%s, \t%s", + i, ip, glb_addr_family_names[backendp[i].inet_family], + glb_state_names[backendp[i].state], + glb_backend_health_status[backendp[i].health]); + } + } + } + + + + /* Number of binds */ + ret = fread(&num_binds, sizeof(uint32_t), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + /* Deal with binds: read & display each bind entry */ + bindp = (bind_entry *)malloc(bfh->max_num_binds * sizeof(bind_entry)); + if (!bindp) { + return -1; + } + + ret = fread(bindp, sizeof(bind_entry), bfh->max_num_binds, in); + if (!glb_fread_ret_check(ret, bfh->max_num_binds, TRUE)) { + free(bindp); + return -1; + } + + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, + table_num)) { + printf("\n\nBinds:"); + + for (i = 0; i < num_binds; i++) { + struct protoent *proto; + + if (glb_ip_addr_to_str(bindp[i].inet_family, &bindp[i].ip, ip)) { + proto = getprotobynumber(bindp[i].ipproto); + printf("\n%40s, %s, Port: %u-%u", + ip, + (proto ? proto->p_name : "Unknown"), + bindp[i].port_start, + bindp[i].port_end); + } + } + } + + free(bindp); + + /* Hash key */ + ret = fread(hash_key, 16, 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, + table_num)) { + printf("\n\nHash-key: 0x"); + for (i = 0; i < 16; i++) { + printf("%x", (unsigned char)hash_key[i]); + } + printf("\n"); + } + /* Deal with the rendezvous hash-table */ + tablep = (table_entry *)malloc(sizeof(table_entry)); + if (!tablep) { + return -1; + } + + for (i = 0; i < bfh->table_entries; i++) { + ret = fread(&tablep->primary_idx, sizeof(uint32_t), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + free(tablep); + return -1; + } + ret = fread(&tablep->secondary_idx, sizeof(uint32_t), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + free(tablep); + return -1; + } + if (cli_config.verbose && \ + FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, + table_num)) { + if (i ==0) { + printf("\n\nForwarding table:"); + } + printf("\nEntry: 0x%x", i); + printf(" %4d", tablep->primary_idx); + printf(" %4d", tablep->secondary_idx); + } + } + free(tablep); + free(backendp); + return 0; +} + +/* + * glb_print_bin_file_header() + * + * Print the contents of the file header + */ +static void +glb_print_bin_file_header(bin_file_header *bfh) +{ + printf("\nFile header"); + printf("\n\tVersion: %u", bfh->file_fmt_ver); + printf("\n\tNumber of tables: %u", bfh->num_tables); + printf("\n\tTable entries: %u", bfh->table_entries); + printf("\n\tMax. # of backends: %u", bfh->max_num_backends); + printf("\n\tMax. # of binds: %u\n", bfh->max_num_binds); +} + +static struct option longopts[] = { + { "detail", no_argument, NULL, 'd' }, + { "num-table", required_argument, NULL, 'n' }, + { "verbose", no_argument, NULL, 'v' }, + { "help", no_argument, NULL, 'h' }, + { NULL, 0, NULL, 0 } +}; + +/* + * Parse the args & determine validity + * + * -d, --detail Print everything other than table-entries + * -n, --num-table Print entries only from table-number specified + * -v, --verbose Print everything + * -h, --help Help + * + * Default behavior: Print only the table-names, VIPs, backends + */ +static int +parse_args(int argc, char **argv, const char **src_binary) +{ + int c; + + cli_config.table_num = FTCTL_TABLE_ENTRIES_ALL; + + while ((c = getopt_long(argc, argv, "n:dvh?", longopts, + NULL)) != -1) { + switch(c) { + case 'd': + cli_config.detailed = TRUE; + break; + + case 'n': + cli_config.table_num = atoi(optarg); + break; + + case 'v': + cli_config.verbose = TRUE; + break; + + case 'h': + case '?': + default: + return(-1); + } + } + + if (optind == argc) { + return(-1); + } + if (cli_config.detailed && cli_config.verbose) { + printf("Mutually exclusive options configured together\n"); + return(-1); + } + *src_binary = argv[optind]; + return(0); +} + + +int +main(int argc, char **argv) +{ + char buffer[256]; + uint32_t i = 0; + bin_file_header *bfh; + size_t ret; + const char *src_binary; + + if (parse_args(argc, argv, &src_binary)) { + glb_ftctl_usage(); + return -1; + } + + + /* Open the binary forwarding table file for reading */ + FILE *in = fopen(src_binary, "rb"); + if (in == NULL) { + printf("Could not open forwarding table file for reading: %s", + src_binary); + return -1; + } + + /* Read magic word */ + ret = fread(buffer, 4, 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + /* Read file header */ + bfh = malloc(sizeof(bin_file_header)); + if (!bfh) { + return -1; + } + ret = fread(bfh, sizeof(bin_file_header), 1, in); + if (!glb_fread_ret_check(ret, 1, TRUE)) { + return -1; + } + + /* Print the header */ + glb_print_bin_file_header(bfh); + + printf("\nNumber of tables: %u", bfh->num_tables); + + if (cli_config.detailed || cli_config.verbose) { + /* For each table, read the fields & display same */ + for (i = 0; i < bfh->num_tables; i++) { + ret = glb_read_per_table_fields(in, bfh, i); + } + } + + free(bfh); + printf("\n"); + return(ret); +} +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/src/glb-director/glb_config_types.h b/src/glb-director/glb_config_types.h new file mode 100644 index 0000000..d8d4c72 --- /dev/null +++ b/src/glb-director/glb_config_types.h @@ -0,0 +1,94 @@ +/* + * BSD 3-Clause License + * + * Copyright (c) 2019 Roblox Corporation. + * Copyright (c) 2018 GitHub. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __GLB_CONFIG_TYPES_H__ + +#define __GLB_CONFIG_TYPES_H__ + +typedef enum {FALSE, TRUE} boolean; + +typedef struct { + uint32_t file_fmt_ver; + uint32_t num_tables; + uint32_t table_entries; + uint32_t max_num_backends; + uint32_t max_num_binds; +} bin_file_header; + +typedef struct { + uint32_t inet_family; + + union { + char v6[16]; + struct { + uint32_t v4; + char reserved[12]; + }; + } ip; + + uint16_t state; + uint16_t health; +} backend_entry; + +typedef struct { + uint32_t inet_family; + + union { + char v6[16]; + struct { + uint32_t v4; + char _[12]; + }; + } ip; + + uint16_t ip_bits; + + uint16_t port_start; + uint16_t port_end; + uint8_t ipproto; + uint8_t reserved; +} bind_entry; + +struct table_entry_ { + uint32_t primary_idx; + uint32_t secondary_idx; +} __attribute__((__packed__)); +typedef struct table_entry_ table_entry; + + +#endif /* __GLB_CONFIG_TYPES_H__ */ +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/src/glb-director/glb_consts.h b/src/glb-director/glb_consts.h new file mode 100644 index 0000000..7928e79 --- /dev/null +++ b/src/glb-director/glb_consts.h @@ -0,0 +1,79 @@ +/* + * BSD 3-Clause License + * + * Copyright (c) 2019 Roblox Corporation. + * Copyright (c) 2018 GitHub. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __GLB_CONSTS_H__ + +#define __GLB_CONSTS_H__ + +#define FILE_FORMAT_VERSION 2 +#define MAX_TABLE_ENTRIES 0x10000 +#define MAX_NUM_BACKENDS 0x100 +#define MAX_NUM_BINDS 0x100 + +// http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml + +typedef enum { + GLB_FAMILY_RESERVED = 0, + GLB_FAMILY_IPV4 = 1, + GLB_FAMILY_IPV6 = 2, + GLB_FAMILY_MAX +} glb_config_addr_family; + +const char *glb_addr_family_names[GLB_FAMILY_MAX] = \ + {"", "IPv4", "IPv6"}; + +typedef enum { + GLB_BACKEND_STATE_FILLING = 0, + GLB_BACKEND_STATE_ACTIVE = 1, + GLB_BACKEND_STATE_DRAINING_INACTIVE = 2, + GLB_BACKEND_STATE_MAX +} glb_config_host_state; + +const char *glb_state_names[GLB_BACKEND_STATE_MAX] = \ + {"Filling", "Active", "Draining_Inactive",}; + +typedef enum { + GLB_BACKEND_HEALTH_DOWN = 0, + GLB_BACKEND_HEALTH_UP = 1, + GLB_BACKEND_HEALTH_MAX = 2 +} glb_config_host_health; + +const char *glb_backend_health_status[GLB_BACKEND_HEALTH_MAX] = \ + {"UnHealthy", "Healthy"}; + +#endif /* __GLB_CONSTS_H__ */ +/* + * Local variables: + * c-indent-level: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/src/glb-director/glb_fwd_config.c b/src/glb-director/glb_fwd_config.c index 67f3c89..537ab61 100644 --- a/src/glb-director/glb_fwd_config.c +++ b/src/glb-director/glb_fwd_config.c @@ -52,6 +52,7 @@ #endif #include "config.h" +#include "glb_consts.h" #include "glb_fwd_config.h" #include "log.h" @@ -362,11 +363,11 @@ int check_config(struct glb_fwd_config_ctx *ctx) int supported_proto(int proto_num) { switch (proto_num) { - case SUPPORTED_PROTOS_ICMP: + case IPPROTO_ICMP: return 0; - case SUPPORTED_PROTOS_TCP: + case IPPROTO_TCP: return 0; - case SUPPORTED_PROTOS_UDP: + case IPPROTO_UDP: return 0; default: return 1; diff --git a/src/glb-director/glb_fwd_config.h b/src/glb-director/glb_fwd_config.h index de1bc5f..72830b7 100644 --- a/src/glb-director/glb_fwd_config.h +++ b/src/glb-director/glb_fwd_config.h @@ -42,22 +42,6 @@ #define FAMILY_IPV4 1 #define FAMILY_IPV6 2 -/* we only support icmp, tcp, udp */ -#define SUPPORTED_PROTOS_ICMP 1 -#define SUPPORTED_PROTOS_TCP 6 -#define SUPPORTED_PROTOS_UDP 17 - -typedef enum { - GLB_BACKEND_STATE_FILLING = 0, - GLB_BACKEND_STATE_ACTIVE = 1, - GLB_BACKEND_STATE_DRAINING = 2, -} glb_fwd_config_host_state; - -typedef enum { - GLB_BACKEND_HEALTH_DOWN = 0, - GLB_BACKEND_HEALTH_UP = 1, -} glb_fwd_config_host_health; - struct glb_fwd_config_content_table_backend { uint32_t family; union { From ebd572c30e82d3643962cb1edfae52c553671579 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Sat, 4 Apr 2020 05:59:00 +0000 Subject: [PATCH 07/11] Fixing the Vagrantfile to ensure that the directors startup fine: the CLI is a dependency for the glb-director package to install proper. --- Vagrantfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Vagrantfile b/Vagrantfile index a4ff68a..6afcf68 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -134,6 +134,7 @@ Vagrant.configure("2") do |config| dpdk-devbind --bind=igb_uio eth1 dpdk-devbind --status + apt install /vagrant/tmp/build/glb-director-cli*.deb apt install /vagrant/tmp/build/glb-director_*.deb apt install /vagrant/tmp/build/glb-healthcheck_*.deb From b83bf900cc04ea30e9f96874800b774eff448d53 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Sat, 4 Apr 2020 19:56:41 +0000 Subject: [PATCH 08/11] 1. Code for generating ftctl as part of the .deb was missed out in the merge. 2. Corrected usage message. --- src/glb-director/ftctl/main.c | 4 ++-- src/glb-director/script/create-packages | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/glb-director/ftctl/main.c b/src/glb-director/ftctl/main.c index c25bb8e..b377dc3 100644 --- a/src/glb-director/ftctl/main.c +++ b/src/glb-director/ftctl/main.c @@ -56,10 +56,10 @@ ftctl_config_t cli_config; */ void glb_ftctl_usage() { - printf("Usage: glb-director-ftctl \n" \ + printf("Usage: glb-ftctl \n" \ " Options: \n" \ " -d, --detail Print everything other than table-entries\n" \ - " -n, --table-num Print forwarding-table entries only for " \ + " -n, --table-num Print information only for " \ "this table (numbering starts with 0)\n" \ " -v, --verbose Print everything\n" \ "\n" \ diff --git a/src/glb-director/script/create-packages b/src/glb-director/script/create-packages index b3811ef..6462276 100755 --- a/src/glb-director/script/create-packages +++ b/src/glb-director/script/create-packages @@ -38,9 +38,11 @@ cd $ROOTDIR make clean make -C cli clean +make -C ftctl clean make make -C cli +make -C ftctl ./cli/glb-director-cli build-config packaging/forwarding_table.json packaging/forwarding_table.bin @@ -51,7 +53,9 @@ fpm -f -s dir -t deb \ --license 'BSD 3-Clause' \ --maintainer 'GitHub ' \ cli/glb-director-cli=/usr/sbin/ \ - cli/glb-config-check=/usr/sbin/ + cli/glb-config-check=/usr/sbin/ \ + ftctl/glb-ftctl=/usr/sbin/ + fpm -f -s dir -t deb \ -n glb-director \ @@ -76,3 +80,4 @@ fi make clean make -C cli clean +make -C ftctl clean From 8fdb332da094d31c281b4060f9f03fe12e368c33 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Sat, 4 Apr 2020 22:00:42 +0000 Subject: [PATCH 09/11] Fixing white-spaces. --- src/glb-director/ftctl/main.c | 58 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/glb-director/ftctl/main.c b/src/glb-director/ftctl/main.c index b377dc3..c193796 100644 --- a/src/glb-director/ftctl/main.c +++ b/src/glb-director/ftctl/main.c @@ -59,8 +59,8 @@ void glb_ftctl_usage() printf("Usage: glb-ftctl \n" \ " Options: \n" \ " -d, --detail Print everything other than table-entries\n" \ - " -n, --table-num Print information only for " \ - "this table (numbering starts with 0)\n" \ + " -n, --table-num Print information only for " \ + "this table (numbering starts with 0)\n" \ " -v, --verbose Print everything\n" \ "\n" \ " Default behavior: Print only the common info\n\n" \ @@ -68,7 +68,7 @@ void glb_ftctl_usage() } /* - * fread_ret_check() + * glb_fread_ret_check() * * Function to check if the returned count by a call to fread() can be * considered proper. @@ -89,7 +89,7 @@ glb_fread_ret_check(size_t ret, size_t num_expect_to_read, return 0; } } - + /* Proper read */ return 1; } @@ -142,12 +142,12 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, backend_entry *backendp; bind_entry *bindp; table_entry *tablep; - + uint32_t num_binds; char hash_key[16]; char ip[INET_ADDRSTRLEN]; size_t ret; - + /* Read the # of backends that this BFT file knows about */ ret = fread(&num_backends, sizeof(uint32_t), 1, in); if (!glb_fread_ret_check(ret, 1, TRUE)) { @@ -156,7 +156,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, /* Deal with backends : read each backend & display same */ backendp = (backend_entry *) malloc(bfh->max_num_backends * \ - sizeof(backend_entry)); + sizeof(backend_entry)); if (!backendp) { return -1; } @@ -164,7 +164,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, if (!glb_fread_ret_check(ret, bfh->max_num_backends, FALSE)) { return -1; } - + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\n*** Table #: %d ***", table_num); @@ -179,15 +179,13 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, } } } - - /* Number of binds */ ret = fread(&num_binds, sizeof(uint32_t), 1, in); if (!glb_fread_ret_check(ret, 1, TRUE)) { return -1; } - + /* Deal with binds: read & display each bind entry */ bindp = (bind_entry *)malloc(bfh->max_num_binds * sizeof(bind_entry)); if (!bindp) { @@ -203,7 +201,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\nBinds:"); - + for (i = 0; i < num_binds; i++) { struct protoent *proto; @@ -217,15 +215,15 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, } } } - + free(bindp); - + /* Hash key */ ret = fread(hash_key, 16, 1, in); if (!glb_fread_ret_check(ret, 1, TRUE)) { return -1; } - + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\nHash-key: 0x"); @@ -239,7 +237,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, if (!tablep) { return -1; } - + for (i = 0; i < bfh->table_entries; i++) { ret = fread(&tablep->primary_idx, sizeof(uint32_t), 1, in); if (!glb_fread_ret_check(ret, 1, TRUE)) { @@ -283,13 +281,14 @@ glb_print_bin_file_header(bin_file_header *bfh) printf("\n\tMax. # of binds: %u\n", bfh->max_num_binds); } -static struct option longopts[] = { - { "detail", no_argument, NULL, 'd' }, - { "num-table", required_argument, NULL, 'n' }, - { "verbose", no_argument, NULL, 'v' }, - { "help", no_argument, NULL, 'h' }, - { NULL, 0, NULL, 0 } -}; +static struct option longopts[] = \ + { + {"detail", no_argument, NULL, 'd'}, + {"num-table", required_argument, NULL, 'n'}, + {"verbose", no_argument, NULL, 'v'}, + { "help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; /* * Parse the args & determine validity @@ -305,9 +304,9 @@ static int parse_args(int argc, char **argv, const char **src_binary) { int c; - + cli_config.table_num = FTCTL_TABLE_ENTRIES_ALL; - + while ((c = getopt_long(argc, argv, "n:dvh?", longopts, NULL)) != -1) { switch(c) { @@ -318,7 +317,7 @@ parse_args(int argc, char **argv, const char **src_binary) case 'n': cli_config.table_num = atoi(optarg); break; - + case 'v': cli_config.verbose = TRUE; break; @@ -356,7 +355,6 @@ main(int argc, char **argv) return -1; } - /* Open the binary forwarding table file for reading */ FILE *in = fopen(src_binary, "rb"); if (in == NULL) { @@ -380,12 +378,12 @@ main(int argc, char **argv) if (!glb_fread_ret_check(ret, 1, TRUE)) { return -1; } - + /* Print the header */ glb_print_bin_file_header(bfh); - + printf("\nNumber of tables: %u", bfh->num_tables); - + if (cli_config.detailed || cli_config.verbose) { /* For each table, read the fields & display same */ for (i = 0; i < bfh->num_tables; i++) { From 97e5eb3e1dcb93a64f6caa066f3c037e29fcecb4 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Sat, 4 Apr 2020 22:03:57 +0000 Subject: [PATCH 10/11] More whitespaces fixed. --- src/glb-director/ftctl/main.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/glb-director/ftctl/main.c b/src/glb-director/ftctl/main.c index c193796..2566d9b 100644 --- a/src/glb-director/ftctl/main.c +++ b/src/glb-director/ftctl/main.c @@ -165,8 +165,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, return -1; } - if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, - table_num)) { + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\n*** Table #: %d ***", table_num); printf("\n\nBackends:"); for (i = 0; i < num_backends; i++) { @@ -198,8 +197,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, return -1; } - if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, - table_num)) { + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\nBinds:"); for (i = 0; i < num_binds; i++) { @@ -224,8 +222,7 @@ glb_read_per_table_fields(FILE *in, const bin_file_header *bfh, return -1; } - if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, - table_num)) { + if (FTCTL_CHECK_IF_ENTRIES_ALL_OR_THIS(cli_config.table_num, table_num)) { printf("\n\nHash-key: 0x"); for (i = 0; i < 16; i++) { printf("%x", (unsigned char)hash_key[i]); From f2a5583b719e6d222f5a0b4993f8a1ea184b8ab1 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Tue, 7 Apr 2020 12:56:39 +0000 Subject: [PATCH 11/11] Removed an unneded header file that had crept in due to chery-picking code. --- src/glb-director/ftctl/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/glb-director/ftctl/main.c b/src/glb-director/ftctl/main.c index 2566d9b..589686b 100644 --- a/src/glb-director/ftctl/main.c +++ b/src/glb-director/ftctl/main.c @@ -35,7 +35,6 @@ #include #include #include -#include "glb-includes/glb_common_includes.h" #include "../glb_consts.h" #include "glb_config_types.h" #include "glb-ftctl.h"