summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-02-26 09:00:20 +0200
committerTimo Teräs <timo.teras@iki.fi>2013-02-26 09:00:20 +0200
commitc43e15006ee6f36f74de12928687f16c8338eadf (patch)
tree1f222a2a3fb5fc6d1ba76932ad93ea2fbc5063ab
parentc242a2754da2c2b965ecc5cd4ae04a07c40ab475 (diff)
downloadsquark-c43e15006ee6f36f74de12928687f16c8338eadf.tar.bz2
squark-c43e15006ee6f36f74de12928687f16c8338eadf.tar.xz
auth-snmp: use ifIndex as ifName if that MIB entry is not support
E.g. HP ProCurve 1800 does not seem to support ifName.
-rw-r--r--src/squark-auth-snmp.c56
1 files changed, 43 insertions, 13 deletions
diff --git a/src/squark-auth-snmp.c b/src/squark-auth-snmp.c
index 2ac1a7f..9a35d33 100644
--- a/src/squark-auth-snmp.c
+++ b/src/squark-auth-snmp.c
@@ -64,6 +64,7 @@
#define SWITCHF_NO_LLDP_MIB 0x01
#define SWITCHF_QBRIDGE_MIB_HAS_VLAN_NUMBER 0x02
#define SWITCHF_BRIDGE_MIB_HAS_VLAN 0x04
+#define SWITCHF_NO_IF_MIB_IFNAME 0x08
/* IANA-AddressFamilyNumbers */
#define IANA_AFN_OTHER 0
@@ -291,6 +292,17 @@ struct auth_context {
struct auth_context * next_sleeper;
};
+void switchinfo_create_ifname(struct auth_context *auth)
+{
+ char name[64];
+
+ if (auth->info_available & FORMAT_PORT_INDEX) {
+ sprintf(name, "%d", auth->local_port);
+ auth->port_name = strdup(name);
+ auth->info_available |= FORMAT_PORT_NAME;
+ }
+}
+
static void cache_update_time(void)
{
current_time = time(NULL);
@@ -695,6 +707,13 @@ static void auth_force_reauthentication(struct auth_context *auth)
snmp_free_pdu(pdu);
}
+static int auth_need_info(struct auth_context *auth, int needed_flags)
+{
+ if ((auth->info_available & needed_flags) == needed_flags)
+ return 0;
+ return username_format_flags & needed_flags;
+}
+
static int auth_handle_portinfo_reply(int oper, netsnmp_session *s, int reqid, netsnmp_pdu *resp, void *data)
{
struct auth_context *auth = data;
@@ -704,18 +723,25 @@ static int auth_handle_portinfo_reply(int oper, netsnmp_session *s, int reqid, n
goto done;
var = resp->variables;
- if (username_format_flags & FORMAT_PORT_NAME)
+ if (auth_need_info(auth, FORMAT_PORT_NAME)) {
auth->port_name = blob_cstr_dup(var_parse_type(&var, ASN_OCTET_STR));
- if (auth->port_name)
- auth->info_available |= FORMAT_PORT_NAME;
- if (username_format_flags & FORMAT_PORT_DESCR)
+ if (auth->port_name) {
+ auth->info_available |= FORMAT_PORT_NAME;
+ } else {
+ auth->current_switch->flags |= SWITCHF_NO_IF_MIB_IFNAME;
+ switchinfo_create_ifname(auth);
+ }
+ }
+ if (auth_need_info(auth, FORMAT_PORT_DESCR)) {
auth->port_descr = blob_cstr_dup(var_parse_type(&var, ASN_OCTET_STR));
- if (auth->port_descr)
- auth->info_available |= FORMAT_PORT_DESCR;
- if (username_format_flags & FORMAT_PORT_WEBAUTH)
+ if (auth->port_descr)
+ auth->info_available |= FORMAT_PORT_DESCR;
+ }
+ if (auth_need_info(auth, FORMAT_PORT_WEBAUTH)) {
auth->webauth_name = blob_cstr_dup(var_parse_type(&var, ASN_OCTET_STR));
- if (auth->webauth_name)
- auth->info_available |= FORMAT_PORT_WEBAUTH;
+ if (auth->webauth_name)
+ auth->info_available |= FORMAT_PORT_WEBAUTH;
+ }
snprintf(auth->status_msg, sizeof(auth->status_msg)-1,
"required info missing: info_available=%08x",
@@ -737,27 +763,31 @@ static void auth_query_port_info(struct auth_context *auth)
oid query_oids[MAX_OID_LEN];
blob_t query;
- if (auth_ok(auth)) {
+ if (si->flags & SWITCHF_NO_IF_MIB_IFNAME)
+ switchinfo_create_ifname(auth);
+
+ if (auth_ok(auth) ||
+ !auth_need_info(auth, FORMAT_PORT_NAME | FORMAT_PORT_DESCR | FORMAT_PORT_WEBAUTH)) {
auth_completed(auth);
return;
}
pdu = snmp_pdu_create(SNMP_MSG_GET);
- if (username_format_flags & FORMAT_PORT_NAME) {
+ if (auth_need_info(auth, FORMAT_PORT_NAME)) {
query = BLOB_OID(query_oids);
blob_push(&query, BLOB_OID(IF_MIB_ifName));
blob_push_oid(&query, auth->local_port);
query = blob_pushed(BLOB_OID(query_oids), query);
snmp_add_null_var(pdu, oid_blob(query));
}
- if (username_format_flags & FORMAT_PORT_DESCR) {
+ if (auth_need_info(auth, FORMAT_PORT_DESCR)) {
query = BLOB_OID(query_oids);
blob_push(&query, BLOB_OID(IF_MIB_ifDescr));
blob_push_oid(&query, auth->local_port);
query = blob_pushed(BLOB_OID(query_oids), query);
snmp_add_null_var(pdu, oid_blob(query));
}
- if (username_format_flags & FORMAT_PORT_WEBAUTH) {
+ if (auth_need_info(auth, FORMAT_PORT_WEBAUTH)) {
query = BLOB_OID(query_oids);
blob_push(&query, BLOB_OID(HP_hpicfUsrAuthWebAuthSessionName));
blob_push_oid(&query, auth->local_port);