From bfe24b138df332188573c92dcb290ec05db74e5b Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 6 Nov 2007 20:53:37 +0000 Subject: [PATCH] Patch #6215: added ifAdminStatus write support (if explicitly enabled by defining SNMP_SAFE_REQUESTS to 0); added code to check link status for ifOperStatus if LWIP_NETIF_LINK_CALLBACK is defined. --- CHANGELOG | 5 +++ src/core/snmp/mib2.c | 80 ++++++++++++++++++++++++++++++++++++++++++ src/include/lwip/opt.h | 9 +++++ 3 files changed, 94 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index e87cdfed..88265982 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,11 @@ HISTORY ++ New features: + 2007-11-06 Simon Goldschmidt + * opt.h, mib2.c: Patch #6215: added ifAdminStatus write support (if explicitly + enabled by defining SNMP_SAFE_REQUESTS to 0); added code to check link status + for ifOperStatus if LWIP_NETIF_LINK_CALLBACK is defined. + 2007-11-06 Simon Goldschmidt * api.h, api_msg.h and dependent files: Task #7410: Removed the need to include core header files in api.h (ip/tcp/udp/raw.h) to hide the internal diff --git a/src/core/snmp/mib2.c b/src/core/snmp/mib2.c index d2959a30..c27bea75 100644 --- a/src/core/snmp/mib2.c +++ b/src/core/snmp/mib2.c @@ -82,6 +82,10 @@ static void interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_d static void interfaces_get_value(struct obj_def *od, u16_t len, void *value); static void ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); static void ifentry_get_value(struct obj_def *od, u16_t len, void *value); +#if !SNMP_SAFE_REQUESTS +static u8_t ifentry_set_test (struct obj_def *od, u16_t len, void *value); +static void ifentry_set_value (struct obj_def *od, u16_t len, void *value); +#endif /* SNMP_SAFE_REQUESTS */ static void atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); static void atentry_get_value(struct obj_def *od, u16_t len, void *value); static void ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); @@ -563,8 +567,13 @@ struct mib_ram_array_node at = { struct mib_list_rootnode iflist_root = { &ifentry_get_object_def, &ifentry_get_value, +#if SNMP_SAFE_REQUESTS &noleafs_set_test, &noleafs_set_value, +#else /* SNMP_SAFE_REQUESTS */ + &ifentry_set_test, + &ifentry_set_value, +#endif /* SNMP_SAFE_REQUESTS */ MIB_NODE_LR, 0, NULL, @@ -2486,6 +2495,27 @@ ifentry_get_value(struct obj_def *od, u16_t len, void *value) ocstrncpy(value,netif->hwaddr,len); break; case 7: /* ifAdminStatus */ +#if LWIP_NETIF_LINK_CALLBACK + { + s32_t *sint_ptr = value; + if (netif_is_up(netif)) + { + if (netif_is_link_up(netif)) + { + *sint_ptr = 1; // up + } + else + { + *sint_ptr = 7; // lowerLayerDown + } + } + else + { + *sint_ptr = 2; // down + } + } + break; +#endif case 8: /* ifOperStatus */ { s32_t *sint_ptr = value; @@ -2581,6 +2611,56 @@ ifentry_get_value(struct obj_def *od, u16_t len, void *value) }; } +#if !SNMP_SAFE_REQUESTS +static u8_t +ifentry_set_test (struct obj_def *od, u16_t len, void *value) +{ + struct netif *netif; + u8_t id, set_ok; + + set_ok = 0; + snmp_ifindextonetif(od->id_inst_ptr[1], &netif); + id = od->id_inst_ptr[0]; + switch (id) + { + case 7: /* ifAdminStatus */ + { + s32_t *sint_ptr = value; + if (*sint_ptr == 1 || *sint_ptr == 2) + set_ok = 1; + } + break; + } + return set_ok; +} + +static void +ifentry_set_value (struct obj_def *od, u16_t len, void *value) +{ + struct netif *netif; + u8_t id; + + snmp_ifindextonetif(od->id_inst_ptr[1], &netif); + id = od->id_inst_ptr[0]; + switch (id) + { + case 7: /* ifAdminStatus */ + { + s32_t *sint_ptr = value; + if (*sint_ptr == 1) + { + netif_set_up(netif); + } + else if (*sint_ptr == 2) + { + netif_set_down(netif); + } + } + break; + } +} +#endif /* SNMP_SAFE_REQUESTS */ + /** * Returns atentry object definitions. * diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index fbb8a392..147a0dd5 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -525,6 +525,15 @@ #define SNMP_PRIVATE_MIB 0 #endif +/** + * Only allow SNMP write actions that are 'safe' (e.g. disabeling netifs is not + * a safe action and disabled when SNMP_SAFE_REQUESTS = 1). + * Unsafe requests are disabled by default! + */ +#ifndef SNMP_SAFE_REQUESTS +#define SNMP_SAFE_REQUESTS 1 +#endif + /* ---------------------------------- ---------- IGMP options ----------