diff --git a/contrib/bsnmp/VERSION b/contrib/bsnmp/VERSION index 809bdcb851df..d3456a90f7d7 100644 --- a/contrib/bsnmp/VERSION +++ b/contrib/bsnmp/VERSION @@ -1 +1 @@ -1.12 +1.13 diff --git a/contrib/bsnmp/gensnmptree/gensnmptree.1 b/contrib/bsnmp/gensnmptree/gensnmptree.1 index c0046b5c8343..0d6b5cda482d 100644 --- a/contrib/bsnmp/gensnmptree/gensnmptree.1 +++ b/contrib/bsnmp/gensnmptree/gensnmptree.1 @@ -2,7 +2,7 @@ .\" Copyright (c) 2001-2005 .\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). .\" All rights reserved. -.\" Copyright (c) 2006 +.\" Copyright (c) 2006,2018 .\" Hartmut Brandt .\" All rights reserved. .\" @@ -31,7 +31,7 @@ .\" .\" $Begemot: gensnmptree.1 383 2006-05-30 07:40:49Z brandt_h $ .\" -.Dd May 26, 2006 +.Dd June 29, 2018 .Dt GENSNMPTREE 1 .Os .Sh NAME @@ -39,7 +39,7 @@ .Nd "generate C and header files from a MIB description file" .Sh SYNOPSIS .Nm -.Op Fl dEehlt +.Op Fl dEeFfhlt .Op Fl I Ar directory .Op Fl i Ar infile .Op Fl p Ar prefix @@ -99,6 +99,26 @@ is the length of the OID. .It Va OID_ Ns Ar name is the last component of the OID. .El +.It Fl F +Together with +.Fl E +causes +.Nm +instead of the generation of enum definitions the generation of +functions for checking a value to be one of the enumeration variants and +for conversion between strings and the enum. The file is sent to standard +output and is meant to be included into a C-file for compilation. +.It Fl f +This flag can be used together with +.Fl E +or when generating the tree files. It causes +.Nm +to emit static inline functions for checking a value to be one of the +enumeration values and for conversion between strings and the enum. +If used when generating the tree files, the preprocessor symbol +.Ar SNMPTREE_TYPES +must be defined when including the tree header file for these definitions +to become visible. .It Fl h Print a short help page. .It Fl I Ar directory @@ -116,6 +136,36 @@ Instead of normal output print the resulting tree. Prefix the file names and the table name with .Ar prefix . .El +.Pp +The following functions are generated by +.Fl f +or +.Fl F : +.Pp +.Ft static inline int +.Fn isok_EnumName "enum EnumName" ; +.Pp +.Ft static inline const char * +.Fn tostr_EnumName "enum EnumName" ; +.Pp +.Ft static inline int +.Fn fromstr_EnumName "const char *" "enum EnumName *" ; +.Pp +The +.Fa EnumName +is replaced with the enumeration name. +.Fn isok_EnumName +returns 1 if the argument is one of the valid enum values and 0 otherwise. +.Fn tostr_EnumName +returns a string representation of the enumeration value. +If the values is not one of the legal values +.Ar EnumName??? +is returned. +.Fn fromstr_EnumName +returns 1 if the string represents one of the legal enumeration values and +0 otherwise. +If 1 is return the variable pointed to by the second argument is set to +the enumeration value. .Sh MIBS The syntax of the MIB description file can formally be specified as follows: .Bd -unfilled -offset indent diff --git a/contrib/bsnmp/gensnmptree/gensnmptree.c b/contrib/bsnmp/gensnmptree/gensnmptree.c index f2dc4fd68c6e..8ec253a604d0 100644 --- a/contrib/bsnmp/gensnmptree/gensnmptree.c +++ b/contrib/bsnmp/gensnmptree/gensnmptree.c @@ -3,7 +3,7 @@ * Fraunhofer Institute for Open Communication Systems (FhG Fokus). * All rights reserved. * - * Copyright (c) 2004-2006 + * Copyright (c) 2004-2006,2018 * Hartmut Brandt. * All rights reserved. * @@ -110,18 +110,21 @@ static int debug; static const char usgtxt[] = "\ Generate SNMP tables.\n\ -usage: gensnmptree [-dEehlt] [-I directory] [-i infile] [-p prefix]\n\ +$Id$\n\ +usage: gensnmptree [-dEeFfhlt] [-I directory] [-i infile] [-p prefix]\n\ [name]...\n\ options:\n\ -d debug mode\n\ - -E extract the named enums and bits only\n\ + -E extract the named or all enums and bits only\n\ -e extract the named oids or enums\n\ + -F generate functions for -E into a .c file\n\ + -f generate functions for -E into the header\n\ -h print this info\n\ -I directory add directory to include path\n\ -i ifile read from the named file instead of stdin\n\ -l generate local include directives\n\ -p prefix prepend prefix to file and variable names\n\ - -t generated a .def file\n\ + -t generate a .def file\n\ "; /* @@ -420,10 +423,9 @@ static const struct { /* arbitrary upper limit on node names and function names */ #define MAXSTR 1000 -char str[MAXSTR]; -u_long val; /* integer values */ -int all_cond; /* all conditions are true */ -int saved_token = -1; +static char str[MAXSTR]; +static u_long val; /* integer values */ +static int saved_token = -1; /* * Report an error and exit. @@ -1065,6 +1067,7 @@ gen_table(FILE *fp, struct node *node) #ifdef HAVE_STDINT_H fprintf(fp, "#include \n"); #endif + fprintf(fp, "#include \n"); if (localincs) { fprintf(fp, "#include \"asn1.h\"\n"); fprintf(fp, "#include \"snmp.h\"\n"); @@ -1191,6 +1194,15 @@ extract(FILE *fp, const struct node *np, struct asn_oid *oid, const char *obj, return (1); } +/** + * Extract the named OID. + * + * \param fp file to extract to + * \param root root of the tree + * \param object name of the object to extract + * + * \return 0 on success, -1 if the object was not found + */ static int gen_extract(FILE *fp, const struct node *root, char *object) { @@ -1378,6 +1390,13 @@ unminus(FILE *fp, const char *s) } } +/** + * Generate a definition for the enum packed into a guard against multiple + * definitions. + * + * \param fp file to write definition to + * \param t type + */ static void gen_enum(FILE *fp, const struct type *t) { @@ -1402,7 +1421,7 @@ gen_enum(FILE *fp, const struct type *t) fprintf(fp, "#define STROFF_%s %ld\n", t->name, min); fprintf(fp, "#define STRING_%s \\\n", t->name); TAILQ_FOREACH(e, &t->enums, link) { - fprintf(fp, "\t[%ld] \"%s_", e->value - min, t->name); + fprintf(fp, "\t[%ld] = \"%s_", e->value - min, t->name); unminus(fp, e->name); fprintf(fp, "\",\\\n"); } @@ -1410,35 +1429,189 @@ gen_enum(FILE *fp, const struct type *t) fprintf(fp, "#endif /* %s_defined__ */\n", t->name); } +/** + * Generate helper functions for an enum. + * + * We always generate a switch statement for the isok function. The compiler + * optimizes this into range checks if possible. + * + * \param fp file to write to + * \param t type + * \param ccode generate externally visible non-inline functions + */ static void -gen_enums(FILE *fp) +gen_enum_funcs(FILE *fp, const struct type *t, int ccode) +{ + fprintf(fp, "\n"); + + if (!ccode) + fprintf(fp, "static inline "); + fprintf(fp, "int\n"); + fprintf(fp, "isok_%s(enum %s s)\n", t->name, t->name); + fprintf(fp, "{\n"); + fprintf(fp, " switch (s) {\n"); + + const struct enums *e; + TAILQ_FOREACH(e, &t->enums, link) { + fprintf(fp, "\t case %s_", t->name); + unminus(fp, e->name); + fprintf(fp, ":\n"); + } + + fprintf(fp, " return (1);\n"); + fprintf(fp, " }\n"); + fprintf(fp, " return (0);\n"); + fprintf(fp, "}\n\n"); + + if (!ccode) + fprintf(fp, "static inline "); + fprintf(fp, "const char *\n"); + fprintf(fp, "tostr_%s(enum %s s)\n", t->name, t->name); + fprintf(fp, "{\n"); + fprintf(fp, " static const char *vals[] = { STRING_%s };\n", t->name); + fprintf(fp, "\n"); + fprintf(fp, " if (isok_%s(s))\n", t->name); + fprintf(fp, " return (vals[(int)s - STROFF_%s]);\n", t->name); + fprintf(fp, " return (\"%s???\");\n", t->name); + fprintf(fp, "}\n\n"); + + if (!ccode) + fprintf(fp, "static inline "); + fprintf(fp, "int\n"); + fprintf(fp, "fromstr_%s(const char *str, enum %s *s)\n", + t->name, t->name); + fprintf(fp, "{\n"); + fprintf(fp, " static const char *vals[] = { STRING_%s };\n", t->name); + fprintf(fp, "\n"); + fprintf(fp, " for (size_t i = 0; i < sizeof(vals)/sizeof(vals[0]); i++) {\n"); + fprintf(fp, " if (vals[i] != NULL && strcmp(vals[i], str) == 0) {\n"); + fprintf(fp, " *s = i + STROFF_%s;\n", t->name); + fprintf(fp, " return (1);\n"); + fprintf(fp, " }\n"); + fprintf(fp, " }\n"); + fprintf(fp, " return (0);\n"); + fprintf(fp, "}\n"); +} + +/** + * Generate helper functions for an enum. This generates code for a c file. + * + * \param fp file to write to + * \param name enum name + */ +static int +gen_enum_funcs_str(FILE *fp, const char *name) +{ + const struct type *t; + + LIST_FOREACH(t, &types, link) + if ((t->is_enum || t->is_bits) && strcmp(t->name, name) == 0) { + gen_enum_funcs(fp, t, 1); + return (0); + } + + return (-1); +} + +/** + * Generate helper functions for all enums. + * + * \param fp file to write to + * \param ccode generate externally visible non-inline functions + */ +static void +gen_all_enum_funcs(FILE *fp, int ccode) { const struct type *t; LIST_FOREACH(t, &types, link) if (t->is_enum || t->is_bits) - gen_enum(fp, t); + gen_enum_funcs(fp, t, ccode); } +/** + * Extract a given enum to the specified file and optionally generate static + * inline helper functions for them. + * + * \param fp file to print on + * \param name name of the enum + * \param gen_funcs generate the functions too + * + * \return 0 if found, -1 otherwise + */ static int -extract_enum(FILE *fp, const char *name) +extract_enum(FILE *fp, const char *name, int gen_funcs) { const struct type *t; LIST_FOREACH(t, &types, link) if ((t->is_enum || t->is_bits) && strcmp(t->name, name) == 0) { gen_enum(fp, t); + if (gen_funcs) + gen_enum_funcs(fp, t, 0); return (0); } return (-1); } +/** + * Extract all enums to the given file and optionally generate static inline + * helper functions for them. + * + * \param fp file to print on + * \param gen_funcs generate the functions too + */ +static void +extract_all_enums(FILE *fp, int gen_funcs) +{ + const struct type *t; + + LIST_FOREACH(t, &types, link) + if (t->is_enum || t->is_bits) { + gen_enum(fp, t); + if (gen_funcs) + gen_enum_funcs(fp, t, 0); + } +} + +/** + * Extract enums and optionally generate some helper functions for them. + * + * \param argc number of arguments + * \param argv arguments (enum names) + * \param gen_funcs_h generate functions into the header file + * \param gen_funcs_c generate a .c file with functions + */ +static void +make_enums(int argc, char *argv[], int gen_funcs_h, int gen_funcs_c) +{ + if (gen_funcs_c) { + if (argc == 0) + gen_all_enum_funcs(stdout, 1); + else { + for (int i = 0; i < argc; i++) + if (gen_enum_funcs_str(stdout, argv[i])) + errx(1, "enum not found: %s", argv[i]); + } + } else { + if (argc == 0) + extract_all_enums(stdout, gen_funcs_h); + else { + for (int i = 0; i < argc; i++) + if (extract_enum(stdout, argv[i], gen_funcs_h)) + errx(1, "enum not found: %s", argv[i]); + } + } +} + int main(int argc, char *argv[]) { int do_extract = 0; int do_tree = 0; int do_enums = 0; + int gen_funcs_h = 0; + int gen_funcs_c = 0; int opt; struct node *root; char fname[MAXPATHLEN + 1]; @@ -1446,17 +1619,13 @@ main(int argc, char *argv[]) FILE *fp; char *infile = NULL; - while ((opt = getopt(argc, argv, "dEehI:i:lp:t")) != EOF) + while ((opt = getopt(argc, argv, "dEeFfhI:i:lp:t")) != EOF) switch (opt) { case 'd': debug = 1; break; - case 'h': - fprintf(stderr, "%s", usgtxt); - exit(0); - case 'E': do_enums = 1; break; @@ -1465,6 +1634,18 @@ main(int argc, char *argv[]) do_extract = 1; break; + case 'F': + gen_funcs_c = 1; + break; + + case 'f': + gen_funcs_h = 1; + break; + + case 'h': + fprintf(stderr, "%s", usgtxt); + exit(0); + case 'I': path_new(optarg); break; @@ -1493,9 +1674,16 @@ main(int argc, char *argv[]) errx(1, "conflicting options -e/-t/-E"); if (!do_extract && !do_enums && argc != optind) errx(1, "no arguments allowed"); - if ((do_extract || do_enums) && argc == optind) + if (do_extract && argc == optind) errx(1, "no objects specified"); + if ((gen_funcs_h || gen_funcs_c) && (do_extract || do_tree)) + errx(1, "-f and -F not allowed with -e or -t"); + if (gen_funcs_c && !do_enums) + errx(1, "-F requires -E"); + if (gen_funcs_h && gen_funcs_c) + errx(1, "-f and -F are mutually exclusive"); + if (infile == NULL) { input_new(stdin, NULL, ""); } else { @@ -1508,7 +1696,8 @@ main(int argc, char *argv[]) while ((tok = gettoken()) != TOK_EOF) merge(&root, parse_top(tok)); - check_tree(root); + if (root) + check_tree(root); if (do_extract) { while (optind < argc) { @@ -1519,11 +1708,8 @@ main(int argc, char *argv[]) return (0); } if (do_enums) { - while (optind < argc) { - if (extract_enum(stdout, argv[optind])) - errx(1, "enum not found: %s", argv[optind]); - optind++; - } + make_enums(argc - optind, argv + optind, + gen_funcs_h, gen_funcs_c); return (0); } if (do_tree) { @@ -1536,7 +1722,7 @@ main(int argc, char *argv[]) gen_header(fp, root, PREFIX_LEN, NULL); fprintf(fp, "\n#ifdef SNMPTREE_TYPES\n"); - gen_enums(fp); + extract_all_enums(fp, gen_funcs_h); fprintf(fp, "\n#endif /* SNMPTREE_TYPES */\n\n"); fprintf(fp, "#define %sCTREE_SIZE %u\n", file_prefix, tree_size); diff --git a/contrib/bsnmp/lib/snmp.h b/contrib/bsnmp/lib/snmp.h index 61e783e76bb0..7db21ae7d8d0 100644 --- a/contrib/bsnmp/lib/snmp.h +++ b/contrib/bsnmp/lib/snmp.h @@ -42,6 +42,9 @@ #include +#define BSNMP_MAJOR 1 +#define BSNMP_MINOR 13 + #define SNMP_COMMUNITY_MAXLEN 128 #define SNMP_MAX_BINDINGS 100 #define SNMP_CONTEXT_NAME_SIZ (32 + 1) diff --git a/contrib/bsnmp/lib/tc.def b/contrib/bsnmp/lib/tc.def index 65f69723c0a6..1930346ecabb 100644 --- a/contrib/bsnmp/lib/tc.def +++ b/contrib/bsnmp/lib/tc.def @@ -38,3 +38,11 @@ typedef RowStatus ENUM ( 6 destroy ) +typedef StorageType ENUM ( + 1 other + 2 volatile + 3 nonVolatile + 4 permanent + 5 readOnly +) + diff --git a/contrib/bsnmp/snmp_mibII/mibII.c b/contrib/bsnmp/snmp_mibII/mibII.c index d6c3ce40b076..bffbd35793c9 100644 --- a/contrib/bsnmp/snmp_mibII/mibII.c +++ b/contrib/bsnmp/snmp_mibII/mibII.c @@ -1772,6 +1772,7 @@ mibII_loading(const struct lmodule *mod, int loaded) mib_unregister_newif(mod); } +extern const struct snmp_module config; const struct snmp_module config = { "This module implements the interface and ip groups.", mibII_init, diff --git a/contrib/bsnmp/snmp_mibII/mibII_route.c b/contrib/bsnmp/snmp_mibII/mibII_route.c index 2d449a364f0c..e8b2535ee88a 100644 --- a/contrib/bsnmp/snmp_mibII/mibII_route.c +++ b/contrib/bsnmp/snmp_mibII/mibII_route.c @@ -47,7 +47,7 @@ struct sroute { uint8_t type; uint8_t proto; }; -RB_HEAD(sroutes, sroute) sroutes = RB_INITIALIZER(&sroutes); +static RB_HEAD(sroutes, sroute) sroutes = RB_INITIALIZER(&sroutes); RB_PROTOTYPE(sroutes, sroute, link, sroute_compare); diff --git a/contrib/bsnmp/snmp_ntp/snmp_ntp.c b/contrib/bsnmp/snmp_ntp/snmp_ntp.c index fcc129a917fa..285168b1d982 100644 --- a/contrib/bsnmp/snmp_ntp/snmp_ntp.c +++ b/contrib/bsnmp/snmp_ntp/snmp_ntp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005 + * Copyright (c) 2005,2018 * Hartmut Brandt. * All rights reserved. * @@ -53,6 +53,8 @@ #include "support.h" #include "snmpmod.h" + +#define SNMPTREE_TYPES #include "ntp_tree.h" #include "ntp_oid.h" diff --git a/contrib/bsnmp/snmp_target/target_snmp.c b/contrib/bsnmp/snmp_target/target_snmp.c index ed8df74fbfdb..7ea47db0491a 100644 --- a/contrib/bsnmp/snmp_target/target_snmp.c +++ b/contrib/bsnmp/snmp_target/target_snmp.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2010 The FreeBSD Foundation + * Copyright (c) 2010,2018 The FreeBSD Foundation * All rights reserved. * * This software was developed by Shteryana Sotirova Shopova under @@ -43,6 +43,7 @@ #include "snmp.h" #include "snmpmod.h" +#define SNMPTREE_TYPES #include "target_tree.h" #include "target_oid.h" @@ -826,9 +827,10 @@ target_dump(void) /* XXX: dump the module stats & list of mgmt targets */ } -const char target_comment[] = \ +static const char target_comment[] = \ "This module implements SNMP Management Target MIB Module defined in RFC 3413."; +extern const struct snmp_module config; const struct snmp_module config = { .comment = target_comment, .init = target_init, diff --git a/contrib/bsnmp/snmp_target/target_tree.def b/contrib/bsnmp/snmp_target/target_tree.def index 990bfac0b06e..14424b00bdc6 100644 --- a/contrib/bsnmp/snmp_target/target_tree.def +++ b/contrib/bsnmp/snmp_target/target_tree.def @@ -29,24 +29,7 @@ # $FreeBSD$ # -#include "tc.def" - -typedef RowStatus ENUM ( - 1 active - 2 notInService - 3 notReady - 4 createAndGo - 5 createAndWait - 6 destroy -) - -typedef StorageType ENUM ( - 1 other - 2 volatile - 3 nonVolatile - 4 permanent - 5 readOnly -) +include "tc.def" (1 internet (6 snmpV2 diff --git a/contrib/bsnmp/snmp_usm/usm_snmp.c b/contrib/bsnmp/snmp_usm/usm_snmp.c index a6c7b8634a1b..149d0f7c6f06 100644 --- a/contrib/bsnmp/snmp_usm/usm_snmp.c +++ b/contrib/bsnmp/snmp_usm/usm_snmp.c @@ -43,6 +43,7 @@ #include "snmp.h" #include "snmpmod.h" +#define SNMPTREE_TYPES #include "usm_tree.h" #include "usm_oid.h" @@ -604,9 +605,10 @@ usm_dump(void) privstr[uuser->suser.priv_proto]); } -const char usm_comment[] = \ +static const char usm_comment[] = \ "This module implements SNMP User-based Security Model defined in RFC 3414."; +extern const struct snmp_module config; const struct snmp_module config = { .comment = usm_comment, .init = usm_init, diff --git a/contrib/bsnmp/snmp_usm/usm_tree.def b/contrib/bsnmp/snmp_usm/usm_tree.def index 72c446e4cc55..84b52956e167 100644 --- a/contrib/bsnmp/snmp_usm/usm_tree.def +++ b/contrib/bsnmp/snmp_usm/usm_tree.def @@ -29,24 +29,7 @@ # $FreeBSD$ # -#include "tc.def" - -typedef RowStatus ENUM ( - 1 active - 2 notInService - 3 notReady - 4 createAndGo - 5 createAndWait - 6 destroy -) - -typedef StorageType ENUM ( - 1 other - 2 volatile - 3 nonVolatile - 4 permanent - 5 readOnly -) +include "tc.def" (1 internet (6 snmpV2 diff --git a/contrib/bsnmp/snmp_vacm/vacm_snmp.c b/contrib/bsnmp/snmp_vacm/vacm_snmp.c index 61142afe1ae9..576495a58889 100644 --- a/contrib/bsnmp/snmp_vacm/vacm_snmp.c +++ b/contrib/bsnmp/snmp_vacm/vacm_snmp.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2010 The FreeBSD Foundation + * Copyright (c) 2010,2018 The FreeBSD Foundation * All rights reserved. * * This software was developed by Shteryana Sotirova Shopova under @@ -43,6 +43,7 @@ #include "snmp.h" #include "snmpmod.h" +#define SNMPTREE_TYPES #include "vacm_tree.h" #include "vacm_oid.h" @@ -1012,9 +1013,10 @@ vacm_dump(void) "excluded":"included"); } -const char vacm_comment[] = \ +static const char vacm_comment[] = \ "This module implements SNMP View-based Access Control Model defined in RFC 3415."; +extern const struct snmp_module config; const struct snmp_module config = { .comment = vacm_comment, .init = vacm_init, diff --git a/contrib/bsnmp/snmp_vacm/vacm_tree.def b/contrib/bsnmp/snmp_vacm/vacm_tree.def index 45b3c335991c..5418a5a6cac1 100644 --- a/contrib/bsnmp/snmp_vacm/vacm_tree.def +++ b/contrib/bsnmp/snmp_vacm/vacm_tree.def @@ -29,24 +29,7 @@ # $FreeBSD$ # -#include "tc.def" - -typedef RowStatus ENUM ( - 1 active - 2 notInService - 3 notReady - 4 createAndGo - 5 createAndWait - 6 destroy -) - -typedef StorageType ENUM ( - 1 other - 2 volatile - 3 nonVolatile - 4 permanent - 5 readOnly -) +include "tc.def" (1 internet (6 snmpV2 diff --git a/contrib/bsnmp/snmpd/main.c b/contrib/bsnmp/snmpd/main.c index 939b350b4200..55c93dcba921 100644 --- a/contrib/bsnmp/snmpd/main.c +++ b/contrib/bsnmp/snmpd/main.c @@ -927,7 +927,7 @@ fd_resume(void *p) #ifdef USE_LIBBEGEMOT if (f->id >= 0) return (0); - if ((f->id = poll_register(f->fd, input, f, POLL_IN)) < 0) { + if ((f->id = poll_register(f->fd, input, f, RPOLL_IN)) < 0) { err = errno; syslog(LOG_ERR, "select fd %d: %m", f->fd); errno = err; diff --git a/contrib/bsnmp/snmpd/trans_udp.c b/contrib/bsnmp/snmpd/trans_udp.c index 5c9a7fd470a2..fa25ee089795 100644 --- a/contrib/bsnmp/snmpd/trans_udp.c +++ b/contrib/bsnmp/snmpd/trans_udp.c @@ -328,7 +328,7 @@ udp_recv(struct tport *tp, struct port_input *pi) sizeof(struct in_addr)); if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDS) - cred = (struct sockcred *)CMSG_DATA(cmsg); + cred = (struct sockcred *)(void *)CMSG_DATA(cmsg); } if (pi->cred) diff --git a/contrib/bsnmp/snmpd/trap.c b/contrib/bsnmp/snmpd/trap.c index 30ff29304d58..396a45c3aeb8 100644 --- a/contrib/bsnmp/snmpd/trap.c +++ b/contrib/bsnmp/snmpd/trap.c @@ -54,6 +54,8 @@ #include "snmpmod.h" #include "snmpd.h" + +#define SNMPTREE_TYPES #include "tree.h" #include "oid.h" diff --git a/contrib/bsnmp/snmpd/tree.def b/contrib/bsnmp/snmpd/tree.def index 2b6a9b98d9a3..cb5d2ec474ce 100644 --- a/contrib/bsnmp/snmpd/tree.def +++ b/contrib/bsnmp/snmpd/tree.def @@ -31,16 +31,7 @@ # System group and private Begemot SNMPd MIB. # -#include "tc.def" - -typedef RowStatus ENUM ( - 1 active - 2 notInService - 3 notReady - 4 createAndGo - 5 createAndWait - 6 destroy -) +include "tc.def" (1 internet (2 mgmt diff --git a/contrib/libbegemot/rpoll.c b/contrib/libbegemot/rpoll.c index 408635e01799..c61b84057eba 100644 --- a/contrib/libbegemot/rpoll.c +++ b/contrib/libbegemot/rpoll.c @@ -44,17 +44,6 @@ # include # include -/* - * There happens to be linuxes which read siginfo.h when including - * signal.h, which, for no appearent reason, defines these symbols. - */ -# ifdef POLL_IN -# undef POLL_IN -# endif -# ifdef POLL_OUT -# undef POLL_OUT -# endif - # include "rpoll.h" /* @@ -339,11 +328,11 @@ poll_build(void) if(p->fd >= 0) { f->fd = p->fd; f->events = 0; - if(p->mask & POLL_IN) + if(p->mask & RPOLL_IN) f->events |= poll_in; - if(p->mask & POLL_OUT) + if(p->mask & RPOLL_OUT) f->events |= poll_out; - if(p->mask & POLL_EXCEPT) + if(p->mask & RPOLL_EXCEPT) f->events |= poll_except; f->revents = 0; p->pfd = f++; @@ -360,11 +349,11 @@ poll_build(void) if(p->fd >= 0) { if(p->fd > maxfd) maxfd = p->fd; - if(p->mask & POLL_IN) + if(p->mask & RPOLL_IN) FD_SET(p->fd, &rset); - if(p->mask & POLL_OUT) + if(p->mask & RPOLL_OUT) FD_SET(p->fd, &wset); - if(p->mask & POLL_EXCEPT) + if(p->mask & RPOLL_EXCEPT) FD_SET(p->fd, &xset); } # endif @@ -582,27 +571,27 @@ poll_dispatch(int wait) # ifdef USE_POLL if(regs[idx].pfd) { - if ((regs[idx].mask & POLL_IN) && + if ((regs[idx].mask & RPOLL_IN) && (regs[idx].pfd->revents & poll_in)) - mask |= POLL_IN; - if ((regs[idx].mask & POLL_OUT) && + mask |= RPOLL_IN; + if ((regs[idx].mask & RPOLL_OUT) && (regs[idx].pfd->revents & poll_out)) - mask |= POLL_OUT; - if((regs[idx].mask & POLL_EXCEPT) && + mask |= RPOLL_OUT; + if((regs[idx].mask & RPOLL_EXCEPT) && (regs[idx].pfd->revents & poll_except)) - mask |= POLL_EXCEPT; + mask |= RPOLL_EXCEPT; } # endif # ifdef USE_SELECT - if ((regs[idx].mask & POLL_IN) && + if ((regs[idx].mask & RPOLL_IN) && FD_ISSET(regs[idx].fd, &nrset)) - mask |= POLL_IN; - if ((regs[idx].mask & POLL_OUT) && + mask |= RPOLL_IN; + if ((regs[idx].mask & RPOLL_OUT) && FD_ISSET(regs[idx].fd, &nwset)) - mask |= POLL_OUT; - if ((regs[idx].mask & POLL_EXCEPT) && + mask |= RPOLL_OUT; + if ((regs[idx].mask & RPOLL_EXCEPT) && FD_ISSET(regs[idx].fd, &nxset)) - mask |= POLL_EXCEPT; + mask |= RPOLL_EXCEPT; # endif assert(idx < regs_alloc); @@ -723,7 +712,7 @@ main(int argc, char *argv[]) { argv = argv; gettimeofday(&start, NULL); - poll_register(0, infunc, NULL, POLL_IN); + poll_register(0, infunc, NULL, RPOLL_IN); if (argc < 2) { t0 = poll_start_timer(1000, 1, tfunc0, "1 second"); diff --git a/contrib/libbegemot/rpoll.h b/contrib/libbegemot/rpoll.h index 497a41ef5eaf..4f0c4e38ec7c 100644 --- a/contrib/libbegemot/rpoll.h +++ b/contrib/libbegemot/rpoll.h @@ -47,16 +47,11 @@ int poll_start_utimer(unsigned long long usecs, int repeat, timer_f func, void *arg); void poll_stop_timer(int); -# if defined(POLL_IN) -# undef POLL_IN -# endif -# if defined(POLL_OUT) -# undef POLL_OUT -# endif - -# define POLL_IN 1 -# define POLL_OUT 2 -# define POLL_EXCEPT 4 +enum { + RPOLL_IN = 1, + RPOLL_OUT = 2, + RPOLL_EXCEPT = 4, +}; extern int rpoll_policy; extern int rpoll_trace; diff --git a/lib/libbsnmp/libbsnmp/Makefile b/lib/libbsnmp/libbsnmp/Makefile index 2a1f9c020c41..c220869c6b2b 100644 --- a/lib/libbsnmp/libbsnmp/Makefile +++ b/lib/libbsnmp/libbsnmp/Makefile @@ -20,9 +20,23 @@ LIBADD= crypto .endif SRCS= asn1.c snmp.c snmpagent.c snmpclient.c snmpcrypto.c support.c +SRCS+= snmptc.h INCS= asn1.h snmp.h snmpagent.h snmpclient.h MAN= asn1.3 bsnmpagent.3 bsnmpclient.3 bsnmplib.3 +snmptc.h : tc.def + (\ + echo -n "/* autogenerated from tc.def; ";\ + ls -l -D "%F %T" ${.ALLSRC} | awk '{printf("%s %s", $$6, $$7)}';\ + echo "*/";\ + echo "#ifndef snmptc_h_1529923773";\ + echo "#define snmptc_h_1529923773";\ + gensnmptree -E -f <${.ALLSRC};\ + echo "#endif" ; \ + ) >${.TARGET} + +CLEANFILES+= snmptc.h + MLINKS+= asn1.3 asn_append_oid.3 MLINKS+= asn1.3 asn_commit_header.3 MLINKS+= asn1.3 asn_compare_oid.3 diff --git a/share/mk/bsd.snmpmod.mk b/share/mk/bsd.snmpmod.mk index 224b82d1ee0b..c45937cc82a7 100644 --- a/share/mk/bsd.snmpmod.mk +++ b/share/mk/bsd.snmpmod.mk @@ -6,14 +6,16 @@ SHLIB_NAME= snmp_${MOD}.so.${SHLIB_MAJOR} SRCS+= ${MOD}_oid.h ${MOD}_tree.c ${MOD}_tree.h CLEANFILES+= ${MOD}_oid.h ${MOD}_tree.c ${MOD}_tree.h CFLAGS+= -I. +GENSNMPTREEFLAGS+= -I${SHAREDIR}/snmpdefs + ${MOD}_oid.h: ${MOD}_tree.def ${EXTRAMIBDEFS} ${EXTRAMIBSYMS} - cat ${.ALLSRC} | gensnmptree -e ${XSYM} > ${.TARGET} + cat ${.ALLSRC} | gensnmptree ${GENSNMPTREEFLAGS} -e ${XSYM} > ${.TARGET} .ORDER: ${MOD}_tree.c ${MOD}_tree.h ${MOD}_tree.h: .NOMETA ${MOD}_tree.c ${MOD}_tree.h: ${MOD}_tree.def ${EXTRAMIBDEFS} - cat ${.ALLSRC} | gensnmptree -p ${MOD}_ + cat ${.ALLSRC} | gensnmptree -f ${GENSNMPTREEFLAGS} -p ${MOD}_ .if defined(DEFS) FILESGROUPS+= DEFS diff --git a/usr.sbin/bsnmpd/bsnmpd/Makefile b/usr.sbin/bsnmpd/bsnmpd/Makefile index d23ee1d0d25a..24d583610993 100644 --- a/usr.sbin/bsnmpd/bsnmpd/Makefile +++ b/usr.sbin/bsnmpd/bsnmpd/Makefile @@ -123,7 +123,6 @@ BMIBSDIR= ${SHAREDIR}/snmp/mibs DEFS= tree.def DEFSDIR= ${SHAREDIR}/snmp/defs -CFLAGS+= -DSNMPTREE_TYPES CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd -I. -DUSE_LIBBEGEMOT CFLAGS+= -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_ERR_H -DHAVE_STRLCPY LIBADD= begemot bsnmp @@ -140,18 +139,15 @@ LIBADD+= wrap .endif oid.h: tree.def Makefile - gensnmptree -e ${XSYM} < ${.ALLSRC:M*.def} > ${.TARGET} + gensnmptree -I${CONTRIB}/lib -e ${XSYM} < ${.ALLSRC:M*.def} > ${.TARGET} .ORDER: tree.c tree.h tree.h: .NOMETA tree.c tree.h: tree.def - gensnmptree -l < ${.ALLSRC} + gensnmptree -I${CONTRIB}/lib -l -f < ${.ALLSRC} MANFILTER= sed -e 's%@MODPATH@%${LIBDIR}/%g' \ -e 's%@DEFPATH@%${DEFSDIR}/%g' \ -e 's%@MIBSPATH@%${BMIBSDIR}/%g' -NO_WCAST_ALIGN= yes -WARNS?= 6 - .include diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile b/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile index 5d0afec43acb..d072c933074f 100644 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile +++ b/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile @@ -5,7 +5,6 @@ MOD= bridge SRCS= bridge_snmp.c bridge_if.c bridge_port.c bridge_addrs.c \ bridge_pf.c bridge_sys.c -CFLAGS+= -DSNMPTREE_TYPES XSYM= dot1dBridge newRoot topologyChange begemotBridgeNewRoot \ begemotBridgeTopologyChange begemotBridgeBaseName diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_addrs.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_addrs.c index c4e969b888e8..ae106015b562 100644 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_addrs.c +++ b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_addrs.c @@ -49,6 +49,7 @@ #include #include +#define SNMPTREE_TYPES #include "bridge_tree.h" #include "bridge_snmp.h" diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_if.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_if.c index bbcfc0db09d5..a9986874b308 100644 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_if.c +++ b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_if.c @@ -50,6 +50,7 @@ #include #include +#define SNMPTREE_TYPES #include "bridge_tree.h" #include "bridge_snmp.h" #include "bridge_oid.h" diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c index 8c07d330ed4a..650b16ff7714 100644 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c +++ b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c @@ -48,6 +48,7 @@ #include #include +#define SNMPTREE_TYPES #include "bridge_tree.h" #include "bridge_snmp.h" diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c index b948236bab69..021cf71a0157 100644 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c +++ b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c @@ -49,6 +49,7 @@ #include #include +#define SNMPTREE_TYPES #include "bridge_tree.h" #include "bridge_snmp.h" diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.c index cf8b36228893..65f7b8e85cc8 100644 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.c +++ b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.c @@ -50,6 +50,7 @@ #include #include +#define SNMPTREE_TYPES #include "bridge_tree.h" #include "bridge_snmp.h" #include "bridge_oid.h" diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_sys.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_sys.c index 4eff1f3c320f..d1ff91c124a6 100644 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_sys.c +++ b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_sys.c @@ -58,6 +58,7 @@ #include #include +#define SNMPTREE_TYPES #include "bridge_tree.h" #include "bridge_snmp.h" diff --git a/usr.sbin/bsnmpd/modules/snmp_hast/Makefile b/usr.sbin/bsnmpd/modules/snmp_hast/Makefile index 9d5fcf3dbcec..72213704e935 100644 --- a/usr.sbin/bsnmpd/modules/snmp_hast/Makefile +++ b/usr.sbin/bsnmpd/modules/snmp_hast/Makefile @@ -27,7 +27,6 @@ CFLAGS+=-DINET6 # This is needed to have WARNS > 1. CFLAGS+=-DYY_NO_UNPUT CFLAGS+=-DYY_NO_INPUT -CFLAGS+= -DSNMPTREE_TYPES LIBADD= util diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/Makefile b/usr.sbin/bsnmpd/modules/snmp_pf/Makefile index efe2e95071e6..fdf77191f706 100644 --- a/usr.sbin/bsnmpd/modules/snmp_pf/Makefile +++ b/usr.sbin/bsnmpd/modules/snmp_pf/Makefile @@ -4,7 +4,6 @@ MOD= pf SRCS= pf_snmp.c -CFLAGS+= -DSNMPTREE_TYPES XSYM= begemotPf DEFS= ${MOD}_tree.def diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c index 9666b0119d96..e79fc2dc24e5 100644 --- a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c +++ b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c @@ -43,6 +43,7 @@ #include #include +#define SNMPTREE_TYPES #include "pf_oid.h" #include "pf_tree.h" diff --git a/usr.sbin/bsnmpd/modules/snmp_target/Makefile b/usr.sbin/bsnmpd/modules/snmp_target/Makefile index b25e9f872453..610e746541f7 100644 --- a/usr.sbin/bsnmpd/modules/snmp_target/Makefile +++ b/usr.sbin/bsnmpd/modules/snmp_target/Makefile @@ -11,9 +11,11 @@ XSYM= snmpTargetMIB snmpNotificationMIB snmpUDPDomain MAN= snmp_target.3 -CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd -DSNMPTREE_TYPES +CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd CFLAGS+= -DHAVE_ERR_H -DHAVE_GETADDRINFO -DHAVE_STRLCPY -DHAVE_SYS_TREE_H +GENSNMPTREEFLAGS+= -I${CONTRIB}/lib + DEFS= ${MOD}_tree.def BMIBS= diff --git a/usr.sbin/bsnmpd/modules/snmp_usm/Makefile b/usr.sbin/bsnmpd/modules/snmp_usm/Makefile index f3c10fa61665..a5e8e8cf9237 100644 --- a/usr.sbin/bsnmpd/modules/snmp_usm/Makefile +++ b/usr.sbin/bsnmpd/modules/snmp_usm/Makefile @@ -13,9 +13,11 @@ XSYM= snmpUsmMIB usmNoAuthProtocol usmHMACMD5AuthProtocol \ MAN= snmp_usm.3 -CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd -DSNMPTREE_TYPES +CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd CFLAGS+= -DHAVE_ERR_H -DHAVE_GETADDRINFO -DHAVE_STRLCPY -DHAVE_SYS_TREE_H +GENSNMPTREEFLAGS+= -I${CONTRIB}/lib + DEFS= ${MOD}_tree.def BMIBS= diff --git a/usr.sbin/bsnmpd/modules/snmp_vacm/Makefile b/usr.sbin/bsnmpd/modules/snmp_vacm/Makefile index b0099fe344b8..d35842bb44f6 100644 --- a/usr.sbin/bsnmpd/modules/snmp_vacm/Makefile +++ b/usr.sbin/bsnmpd/modules/snmp_vacm/Makefile @@ -11,9 +11,11 @@ XSYM= snmpVacmMIB MAN= snmp_vacm.3 -CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd -DSNMPTREE_TYPES +CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd CFLAGS+= -DHAVE_ERR_H -DHAVE_GETADDRINFO -DHAVE_STRLCPY -DHAVE_SYS_TREE_H +GENSNMPTREEFLAGS+= -I${CONTRIB}/lib + DEFS= ${MOD}_tree.def BMIBS= diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile b/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile index 6a53d46fb297..eb6b230210e9 100644 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile +++ b/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile @@ -4,7 +4,6 @@ MOD= wlan SRCS= wlan_snmp.c wlan_sys.c -CFLAGS+= -DSNMPTREE_TYPES XSYM= begemotWlan diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.c b/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.c index 09f6a86967ae..aa156a2f2321 100644 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.c +++ b/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.c @@ -52,6 +52,7 @@ #include #include +#define SNMPTREE_TYPES #include "wlan_tree.h" #include "wlan_snmp.h" #include "wlan_oid.h" diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_sys.c b/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_sys.c index 93e256621af4..c714f1fa4211 100644 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_sys.c +++ b/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_sys.c @@ -58,6 +58,7 @@ #include #include +#define SNMPTREE_TYPES #include "wlan_tree.h" #include "wlan_snmp.h"