]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
snmp_log() wrapper
authorVojtech Vilimek <vojtech.vilimek@nic.cz>
Sat, 10 Dec 2022 12:22:37 +0000 (13:22 +0100)
committerVojtech Vilimek <vojtech.vilimek@nic.cz>
Sat, 10 Dec 2022 12:22:37 +0000 (13:22 +0100)
proto/snmp/bgp_mib.c
proto/snmp/snmp.c
proto/snmp/snmp.h
proto/snmp/subagent.c
proto/snmp/subagent.h

index 5be28da84f34618de69b386f9ec4b121d5deb179..3018809de131e881f6a9b2b604f4c118d0c85a71 100644 (file)
@@ -114,52 +114,51 @@ print_bgp_record(struct bgp_config *config)
   struct bgp_proto *bgp_proto = (struct bgp_proto *) cf->proto;
   struct bgp_conn *conn = bgp_proto->conn;
 
-  log(L_INFO "    name: %s", cf->name);
-  log(L_INFO "");
-  log(L_INFO "    rem. identifier: %u", bgp_proto->remote_id);
-  log(L_INFO "    local ip: %I", config->local_ip);
-  log(L_INFO "    remote ip: %I", config->remote_ip);
-  log(L_INFO "    local port: %u", config->local_port);
-  log(L_INFO "    remote port: %u", config->remote_port);
+  snmp_log("    name: %s", cf->name);
+  snmp_log("");
+  snmp_log("    rem. identifier: %u", bgp_proto->remote_id);
+  snmp_log("    local ip: %I", config->local_ip);
+  snmp_log("    remote ip: %I", config->remote_ip);
+  snmp_log("    local port: %u", config->local_port);
+  snmp_log("    remote port: %u", config->remote_port);
 
   // crashes ?
   if (conn) {
-    log(L_INFO "    state: %u", conn->state);
-    log(L_INFO "    remote as: %u", conn->remote_caps->as4_number);
+    snmp_log("    state: %u", conn->state);
+    snmp_log("    remote as: %u", conn->remote_caps->as4_number);
   }
 
 
-  log(L_INFO "    in updates: %u", bgp_proto->stats.rx_updates);
-  log(L_INFO "    out updates: %u", bgp_proto->stats.tx_updates);
-  log(L_INFO "    in total: %u", bgp_proto->stats.rx_messages);
-  log(L_INFO "    out total: %u", bgp_proto->stats.tx_messages);
-  log(L_INFO "    fsm transitions: %u",
+  snmp_log("    in updates: %u", bgp_proto->stats.rx_updates);
+  snmp_log("    out updates: %u", bgp_proto->stats.tx_updates);
+  snmp_log("    in total: %u", bgp_proto->stats.rx_messages);
+  snmp_log("    out total: %u", bgp_proto->stats.tx_messages);
+  snmp_log("    fsm transitions: %u",
 bgp_proto->stats.fsm_established_transitions);
 
   // not supported yet
-  log(L_INFO "    fsm total time: --");
-  log(L_INFO "    retry interval: %u", config->connect_retry_time);
+  snmp_log("    fsm total time: --");
+  snmp_log("    retry interval: %u", config->connect_retry_time);
 
-  log(L_INFO "    hold configurated: %u", config->hold_time );
-  log(L_INFO "    keep alive config: %u", config->keepalive_time );
+  snmp_log("    hold configurated: %u", config->hold_time );
+  snmp_log("    keep alive config: %u", config->keepalive_time );
 
   // unknown
-  log(L_INFO "    min AS origin. int.: --");
-  log(L_INFO "    min route advertisement: %u", 0 );
-  log(L_INFO "    in update elapsed time: %u", 0 );
+  snmp_log("    min AS origin. int.: --");
+  snmp_log("    min route advertisement: %u", 0 );
+  snmp_log("    in update elapsed time: %u", 0 );
 
   if (!conn)
-    log(L_INFO "  no connection established");
-
-  log(L_INFO "  outgoinin_conn state %u", bgp_proto->outgoing_conn.state + 1);
-  log(L_INFO "  incoming_conn state: %u", bgp_proto->incoming_conn.state + 1);
+    snmp_log("  no connection established");
 
+  snmp_log("  outgoinin_conn state %u", bgp_proto->outgoing_conn.state + 1);
+  snmp_log("  incoming_conn state: %u", bgp_proto->incoming_conn.state + 1);
 }
 
 static void
 print_bgp_record_all(struct snmp_proto *p)
 {
-  log(L_INFO "dumping watched bgp status");
+  snmp_log("dumping watched bgp status");
   HASH_WALK(p->bgp_hash, next, peer)
   {
     print_bgp_record(peer->config);
@@ -468,15 +467,15 @@ update_bgp_oid(struct oid *oid, u8 state)
 static struct oid *
 bgp_find_dynamic_oid(struct snmp_proto *p, struct oid *o_start, struct oid *o_end, u8 state UNUSED)
 {
-  log(L_INFO "bgp_find_dynamic_oid()");
+  snmp_log("bgp_find_dynamic_oid()");
   ip4_addr ip4 = ip4_from_oid(o_start);
   ip4_addr dest = ip4_from_oid(o_end);
 
-  log(L_INFO "ip addresses build");
+  snmp_log("ip addresses build");
   net_addr *net = mb_allocz(p->p.pool, sizeof(struct net_addr));
   net_fill_ip4(net, ip4, IP4_MAX_PREFIX_LENGTH);
 
-  log(L_INFO "dynamic part of BGP mib");
+  snmp_log("dynamic part of BGP mib");
 
   struct f_trie_walk_state *ws = mb_allocz(p->p.pool,
                                           sizeof(struct f_trie_walk_state));
@@ -566,7 +565,7 @@ static byte *
 bgp_fill_dynamic(struct snmp_proto *p, struct agentx_varbind *vb, byte *pkt, uint size
 UNUSED, uint contid UNUSED, int byte_ord UNUSED, u8 state)
 {
-  //log(L_INFO "bgp_fill_dynamic() valid ip %s", snmp_bgp_valid_ip4(oid) ? "true" : "false");
+  //snmp_log("bgp_fill_dynamic() valid ip %s", snmp_bgp_valid_ip4(oid) ? "true" : "false");
 
   struct oid *oid = &vb->name;
 
@@ -579,7 +578,7 @@ UNUSED, uint contid UNUSED, int byte_ord UNUSED, u8 state)
     return pkt;
   }
 
-  log(L_INFO " -> ip addr %I", addr);
+  snmp_log(" -> ip addr %I", addr);
   // TODO XXX deal with possible change of (remote) ip
   struct snmp_bgp_peer *pe = HASH_FIND(p->bgp_hash, SNMP_HASH, addr);
 
@@ -777,7 +776,7 @@ static byte *
 bgp_fill_static(struct snmp_proto *p, struct agentx_varbind *vb, byte *pkt, uint size
 UNUSED, uint contid UNUSED, int byte_ord UNUSED, u8 state)
 {
-  log(L_INFO "snmp bgp_fill_static ()\n");
+  snmp_log("snmp bgp_fill_static ()\n");
 
   struct oid *oid = &vb->name;
 
@@ -812,7 +811,7 @@ UNUSED, uint contid UNUSED, int byte_ord UNUSED, u8 state)
       vb->type = AGENTX_NO_SUCH_OBJECT;
   }
 
-  log(L_INFO "snmp ended with non empty pkt\n");
+  snmp_log("snmp ended with non empty pkt\n");
   return pkt;
 }
 
@@ -821,7 +820,7 @@ snmp_bgp_fill(struct snmp_proto *p, struct agentx_varbind *vb, byte *buf UNUSED,
 uint size UNUSED, uint contid UNUSED, int byte_ord UNUSED)
 {
   u8 state = snmp_bgp_state(&vb->name);
-  //log(L_INFO "snmp_bgp_fill() state %u is dynamic %s has value %s", state, is_dynamic(state) ? "true" : "false", snmp_bgp_has_value(state) ? "true" : "false");
+  //snmp_log("snmp_bgp_fill() state %u is dynamic %s has value %s", state, is_dynamic(state) ? "true" : "false", snmp_bgp_has_value(state) ? "true" : "false");
 
   if (!is_dynamic(state))
     return bgp_fill_static(p, vb, buf, size, contid, byte_ord, state);
@@ -835,7 +834,7 @@ uint size UNUSED, uint contid UNUSED, int byte_ord UNUSED)
   }
   /*
   {
-    log(L_INFO "has no value");
+    snmp_log("has no value");
     struct agentx_varbind *vb = snmp_create_varbind(buf, oid);
     buf += snmp_varbind_size(vb);
     vb->type = AGENTX_NO_SUCH_OBJECT;
index 72a82c44329fb64c5ad1b6cb522cdf0999a8a85f..cf6d261229fbdee7ccaf44d288c1e703f0d53bb7 100644 (file)
@@ -45,12 +45,13 @@ snmp_init(struct proto_config *CF)
   p->remote_ip = cf->remote_ip;
   p->local_port = cf->local_port;
   p->remote_port = cf->remote_port;
+  snmp_log("chaning proto_snmp state to INIT");
   p->state = SNMP_INIT;
 
   // p->timeout = cf->timeout;
   p->timeout = 15;
 
-  log(L_INFO "snmp_reconfigure() lip: %I:%u rip: %I:%u",
+  snmp_log("snmp_reconfigure() lip: %I:%u rip: %I:%u",
     cf->local_ip, cf->local_port, cf->remote_ip, cf->remote_port);
 
   return P;
@@ -59,7 +60,7 @@ snmp_init(struct proto_config *CF)
 static void
 snmp_startup_timeout(timer *t)
 {
-  log(L_INFO "startup timer triggered");
+  snmp_log("startup timer triggered");
   snmp_startup(t->data);
 }
 
@@ -70,9 +71,9 @@ snmp_startup(struct snmp_proto *p)
 
   /* starting agentX communicaiton channel */
 
-  log(L_INFO "preparing lock");
+  snmp_log("preparing lock");
   struct object_lock *lock;
-  log(L_INFO "snmp_startup() object lock state %p", p->lock);
+  snmp_log("snmp_startup() object lock state %p", p->lock);
 
   /* we could have the lock already acquired but be in ERROR state */
   lock = p->lock = olock_new(p->p.pool);
@@ -81,17 +82,19 @@ snmp_startup(struct snmp_proto *p)
   lock->hook = snmp_start_locked;
   lock->data = p;
 
+  snmp_log("lock acquiring");
   olock_acquire(lock);
-  log(L_INFO "lock acquiring");
 
-  log(L_INFO "local ip: %I:%u, remote ip: %I:%u",
+  /*
+  snmp_log("local ip: %I:%u, remote ip: %I:%u",
     p->local_ip, p->local_port, p->remote_ip, p->remote_port);
+  */
 }
 
 static void
 snmp_start_locked(struct object_lock *lock)
 {
-  log(L_INFO "snmp_start_locked() - preparing socket ");
+  snmp_log("snmp_start_locked() - lock acquired; preparing socket ");
   struct snmp_proto *p = lock->data;
 
   sock *s = sk_new(p->p.pool);
@@ -118,21 +121,20 @@ snmp_start_locked(struct object_lock *lock)
   if (sk_open(s) < 0)
     log(L_ERR "Cannot open listening socket");
 
-  log(L_INFO "socket ready!, trying to connect");
+  snmp_log("socket ready!, trying to connect");
 }
 
 static void
 snmp_tx(sock *sk UNUSED)
 {
-  log(L_INFO "snmp_tx() something, yay!");
+  snmp_log("snmp_tx() something, yay!");
 }
 
-
 static void
 snmp_connected(sock *sk)
 {
   struct snmp_proto *p = sk->data;
-  log(L_INFO "snmp_connected() connection created");
+  snmp_log("snmp_connected() connection created");
   byte *buf UNUSED = sk->rbuf;
 
   sk->rx_hook = snmp_rx;
@@ -144,7 +146,7 @@ snmp_connected(sock *sk)
 static void
 snmp_sock_err(sock *sk, int err)
 {
-  log(L_INFO "snmp_sock_err() %s - err no: %d",  strerror(err), err);
+  snmp_log("snmp_sock_err() %s - err no: %d",  strerror(err), err);
 
   struct snmp_proto *p = sk->data;
   tm_stop(p->ping_timer);
@@ -155,6 +157,7 @@ snmp_sock_err(sock *sk, int err)
   rfree(p->lock);
   p->lock = NULL;
 
+  snmp_log("changing proto_snmp state to ERR[OR]");
   p->state = SNMP_ERR;
   tm_start(p->startup_timer, 15 S);
 }
@@ -162,7 +165,7 @@ snmp_sock_err(sock *sk, int err)
 static int
 snmp_start(struct proto *P)
 {
-  log(L_INFO "snmp_start() - starting timer (almost)");
+  snmp_log("snmp_start() - starting timer (almost)");
   struct snmp_proto *p = (void *) P;
   struct snmp_config *cf = (struct snmp_config *) P->cf;
 
@@ -179,7 +182,7 @@ snmp_start(struct proto *P)
 
 
   /* starting agentX communicaiton channel */
-  log(L_INFO "preparing lock");
+  snmp_log("preparing lock");
   struct object_lock *lock;
   lock = p->lock = olock_new(p->p.pool);
 
@@ -188,9 +191,9 @@ snmp_start(struct proto *P)
   lock->data = p;
 
   olock_acquire(lock);
-  log(L_INFO "lock acquired");
+  snmp_log("lock acquired");
 
-  log(L_INFO "local ip: %I:%u, remote ip: %I:%u",
+  snmp_log("local ip: %I:%u, remote ip: %I:%u",
     p->local_ip, p->local_port, p->remote_ip, p->remote_port);
 
   /* create copy of bonds to bgp */
@@ -234,8 +237,9 @@ snmp_reconfigure(struct proto *P, struct proto_config *CF)
 
   /* TODO walk all bind protocols and find their (new) IP
     to update HASH table */
-  log(L_INFO "snmp_reconfigure() lip: %I:%u rip: %I:%u",
+  snmp_log("snmp_reconfigure() lip: %I:%u rip: %I:%u",
     p->local_ip, p->local_port, p->remote_ip, p->remote_port);
+
   return 1;
 }
 
@@ -319,7 +323,7 @@ snmp_postconfig(struct proto_config *CF)
 static void
 snmp_ping_timer(struct timer *tm)
 {
-  log(L_INFO "snmp_ping_timer() ");
+  snmp_log("snmp_ping_timer() ");
   struct snmp_proto *p = tm->data;
 
   if (p->state == SNMP_CONN)
index 4b797888705da517a48b299c3ce449c9a9af9b14..5960d3d713a5f77f7b8fc02e3a486fe622928cfb 100644 (file)
@@ -91,7 +91,8 @@ struct snmp_proto {
   u32 packet_id;
 
   //struct iface *iface;
-  // map goes here
+
+  // map
   struct f_trie *bgp_trie;
   HASH(struct snmp_bgp_peer) bgp_hash;
   struct tbf rl_gen;
@@ -106,6 +107,4 @@ struct snmp_proto {
   uint errs;
 };
 
-#define snmp_log(x) log(L_INFO "snmp" x);
-
 #endif
index ffbb3f96e4315403487d0cce98da45223681b968..a91da7e471fdf075067c0d62829f19895c55beac 100644 (file)
@@ -70,7 +70,7 @@ open_pdu(struct snmp_proto *p, struct oid *oid)
 
   if (size > AGENTX_HEADER_SIZE + snmp_oid_size(oid) + snmp_str_size(str))
   {
-    log(L_INFO "open_pdu()");
+    snmp_log("open_pdu()");
 
     struct agentx_header *h;
     SNMP_CREATE(pkt, struct agentx_header, h)
@@ -89,15 +89,15 @@ open_pdu(struct snmp_proto *p, struct oid *oid)
     int ret = sk_send(sk, pkt - buf);
 
     if (ret == 0)
-      log(L_INFO "sk_send sleep");
+      snmp_log("sk_send sleep");
     else if (ret < 0)
-      log(L_INFO "sk_send err %d", ret);
+      snmp_log("sk_send err %d", ret);
     else
-      log(L_INFO "sk_send ok !!! ");
+      snmp_log("sk_send ok !!! ");
   }
 
   else
-    log(L_INFO "open_pdu() insufficient size, %u <= %u ",
+    snmp_log("open_pdu() insufficient size, %u <= %u ",
        size, AGENTX_HEADER_SIZE + snmp_oid_size(oid) + snmp_str_size(str));
 }
 
@@ -112,7 +112,7 @@ de_allocate_pdu(struct snmp_proto *p, struct oid *oid, u8 type)
 
   if (size > AGENTX_HEADER_SIZE + )
   {
-    log(L_INFO "de_allocate_pdu()");
+    snmp_log("de_allocate_pdu()");
 
     struct agentx_header *h;
     SNMP_CREATE(pkt, struct agentx_header, h);
@@ -125,7 +125,7 @@ de_allocate_pdu(struct snmp_proto *p, struct oid *oid, u8 type)
   }
 
   else
-    log(L_INFO "de_allocate_pdu(): insufficient size");
+    snmp_log("de_allocate_pdu(): insufficient size");
 }
 */
 
@@ -141,7 +141,7 @@ un_register_pdu(struct snmp_proto *p, struct oid *oid, uint index, uint len, u8
   /* conditional +4 for upper-bound */
   if (size > AGENTX_HEADER_SIZE + snmp_oid_size(oid) + ((len > 1) ? 4 : 0))
   {
-    log(L_INFO "un_register_pdu()");
+    snmp_log("un_register_pdu()");
     struct agentx_un_register_pdu *ur;
     SNMP_CREATE(pkt, struct agentx_un_register_pdu, ur);
     struct agentx_header *h = &ur->h;
@@ -157,7 +157,7 @@ un_register_pdu(struct snmp_proto *p, struct oid *oid, uint index, uint len, u8
     STORE(ur->range_subid, (len > 1) ? index : 0);
 
     pkt = snmp_put_oid(pkt, oid);
-    log(L_INFO "pkt - buf : %lu sizeof %u", pkt -buf, AGENTX_HEADER_SIZE);
+    snmp_log("pkt - buf : %lu sizeof %u", pkt -buf, AGENTX_HEADER_SIZE);
 
     /* place upper-bound if needed */
     if (len > 1)
@@ -170,21 +170,21 @@ un_register_pdu(struct snmp_proto *p, struct oid *oid, uint index, uint len, u8
     SNMP_UPDATE(h, snmp_pkt_len(buf, pkt));
 
     for (uint i = 0; i < pkt - buf; i++)
-      log(L_INFO "%p:  %02X", buf+i, *(buf + i));
+      snmp_log("%p:  %02X", buf+i, *(buf + i));
 
-    log(L_INFO "sending (un)register %d", type);
+    snmp_log("sending (un)register %d", type);
     int ret = sk_send(sk, pkt - buf);
 
     if (ret == 0)
-      log(L_INFO "sk_send sleep");
+      snmp_log("sk_send sleep");
     else if (ret < 0)
-      log(L_INFO "sk_send err %d", ret);
+      snmp_log("sk_send err %d", ret);
     else
-      log(L_INFO "sk_send ok !!");
+      snmp_log("sk_send ok !!");
   }
 
   else
-    log(L_INFO "un_register_pdu() insufficient size");
+    snmp_log("un_register_pdu() insufficient size");
 }
 
 /* register pdu */
@@ -209,7 +209,7 @@ close_pdu(struct snmp_proto *p, u8 reason)
   byte *buf, *pkt;
   buf = pkt = sk->tbuf;
   uint size = sk->tbsize;
-  log(L_INFO "close_pdu() size: %u %c %u", size, (size > AGENTX_HEADER_SIZE + 4)
+  snmp_log("close_pdu() size: %u %c %u", size, (size > AGENTX_HEADER_SIZE + 4)
 ? '>':'<', AGENTX_HEADER_SIZE);
 
   /* +4B for reason */
@@ -225,13 +225,13 @@ close_pdu(struct snmp_proto *p, u8 reason)
 
     SNMP_UPDATE(h, snmp_pkt_len(buf, pkt));
 
-    log(L_INFO "preparing to sk_send()");
+    snmp_log("preparing to sk_send()");
     int ret = sk_send(sk, pkt - buf);
 
     if (ret == 0)
-      log(L_INFO "sk_send sleep");
+      snmp_log("sk_send sleep");
     else if (ret < 0)
-      log(L_INFO "sk_send err");
+      snmp_log("sk_send err");
     else
       log(L_INFO, "sk_send ok !!");
   }
@@ -253,7 +253,7 @@ parse_pkt(struct snmp_proto *p, byte *buf, uint size)
 
   uint len = 0;
   struct agentx_header *h = (void *) buf;
-  log(L_INFO "parse_pkt got type %u", h->type);
+  snmp_log("parse_pkt got type %u", h->type);
   switch (h->type)
   {
     case AGENTX_RESPONSE_PDU:
@@ -277,18 +277,18 @@ parse_pkt(struct snmp_proto *p, byte *buf, uint size)
       die("unknown packet type %u", h->type);
   }
 
-  log(L_INFO "parsed, sending ... to addr %I:%u -> %I:%u",
+  snmp_log("parsed, sending ... to addr %I:%u -> %I:%u",
     p->sock->saddr, p->sock->sport, p->sock->daddr, p->sock->dport);
   if (len && p->state != SNMP_ERR)
   {
     p->to_send = len;
     int ret = sk_send(p->sock, len);
-    log(L_INFO "message sent");
+    snmp_log("message sent");
 
     if (ret == 0)
-      log(L_INFO "sk_send sleep");
+      snmp_log("sk_send sleep");
     else if (ret < 0)
-      log(L_INFO "sk_send err no: %d '%s'", ret, strerror(ret));
+      snmp_log("sk_send err no: %d '%s'", ret, strerror(ret));
     else
       log("sk_send OK ! !!");
   }
@@ -305,18 +305,18 @@ parse_response(struct snmp_proto *p, byte *buf, uint size)
   struct agentx_response *r = (void *) buf;
   struct agentx_header *h = &r->h;
 
-  log(L_INFO "endianity: %s, session %u, transaction: %u", (h->flags & AGENTX_NETWORK_BYTE_ORDER) ? "big end":
+  snmp_log("endianity: %s, session %u, transaction: %u", (h->flags & AGENTX_NETWORK_BYTE_ORDER) ? "big end":
 "little end", h->session_id, h->transaction_id);
-  log(L_INFO "sid: %3u\ttid: %3u\tpid: %3u\t", p->session_id, p->transaction_id,
+  snmp_log("sid: %3u\ttid: %3u\tpid: %3u\t", p->session_id, p->transaction_id,
 p->packet_id);
 
-  log(L_INFO "size %u", h->payload);
-  log(L_INFO "uptime: %u s", r->uptime);
+  snmp_log("size %u", h->payload);
+  snmp_log("uptime: %u s", r->uptime);
 
   if (r->err == AGENTX_RES_NO_ERROR)
     do_response(p, buf, size);
   else
-    log(L_INFO "an error occured '%s'", snmp_errs[get_u16(&r->err) -
+    snmp_log("an error occured '%s'", snmp_errs[get_u16(&r->err) -
 SNMP_ERR_SHIFT]);
 
   return 1;
@@ -345,7 +345,7 @@ do_response(struct snmp_proto *p, byte *buf, uint size UNUSED)
 
       p->transaction_id++;
 
-      log(L_INFO "sending register-pdu");
+      snmp_log("sending register-pdu");
 
       // register whole BGP4-MIB
       u32 arr_bgp[] = {1, 15, 1};
@@ -380,30 +380,32 @@ do_response(struct snmp_proto *p, byte *buf, uint size UNUSED)
       // TODO register all bind bgp connections
       snmp_register(p, o2, 9, 24);
 
-      log(L_INFO "before hash walk");
+      snmp_log("before hash walk");
       HASH_WALK(p->bgp_hash, next, peer)
       {
        snmp_oid_ip4_index(o2, 5, ipa_to_ip4(peer->peer_ip));
 
-       log(L_INFO "");
-       log(L_INFO "o2 n_subid %u prefix %u include %u", o2->n_subid,
+       snmp_log("");
+       snmp_log("o2 n_subid %u prefix %u include %u", o2->n_subid,
          o2->prefix, o2->include);
        for (int i = 0; i < o2->n_subid; i++)
-         log(L_INFO "%d: %u", i, o2->ids[i]);
-       log(L_INFO "");
+         snmp_log("%d: %u", i, o2->ids[i]);
+       snmp_log("");
 
        snmp_register(p, o2, 9, 24);
       }
       HASH_WALK_END;
-      log(L_INFO "after hash walk");
+      snmp_log("after hash walk");
 
       mb_free(o2);
 
+      snmp_log("changing proto_snmp state to REGISTER");
       p->state = SNMP_REGISTR;
       //proto_notify_state(&p->p, PS_UP);
       break;
 
     case SNMP_REGISTR:
+      snmp_log("chaning proto_snmp state to CONNECTED");
       p->state = SNMP_CONN;
       break;
 
@@ -418,7 +420,7 @@ do_response(struct snmp_proto *p, byte *buf, uint size UNUSED)
 static uint UNUSED
 parse_get_pdu(struct snmp_proto *p, byte *buf, uint size)
 {
-  log(L_INFO "parse_get_pdu()");
+  snmp_log("parse_get_pdu()");
 
   sock *sk = p->sock;
   byte *res_pkt, *res = sk->tbuf;
@@ -427,25 +429,25 @@ parse_get_pdu(struct snmp_proto *p, byte *buf, uint size)
   if (size < AGENTX_HEADER_SIZE)
     return 0;
 
-  log(L_INFO "Get-PDU enough room %p", buf);
+  snmp_log("Get-PDU enough room %p", buf);
 
   struct agentx_header *h = (void *) buf;
   ADVANCE(buf, size, AGENTX_HEADER_SIZE);
-  log(L_INFO "advancing %p cause %u", buf, AGENTX_HEADER_SIZE);
+  snmp_log("advancing %p cause %u", buf, AGENTX_HEADER_SIZE);
 
   int byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER;
 
   byte *pkt = buf;
   uint pkt_size = LOAD(h->payload, byte_ord);
-  log(L_INFO "RX packet size is %u", pkt_size);
+  snmp_log("RX packet size is %u", pkt_size);
 
   uint clen;         /* context len */
   char *context = NULL;
   SNMP_LOAD_CONTEXT(p, h, pkt, context, clen)
-  log(L_INFO "after context load %p, pkt == buf %d", pkt, pkt == buf);
+  snmp_log("after context load %p, pkt == buf %d", pkt, pkt == buf);
 
   res_pkt = prepare_response(p, res, rsize);
-  log(L_INFO "response header created: %p (%u)", res_pkt, res_pkt - res);
+  snmp_log("response header created: %p (%u)", res_pkt, res_pkt - res);
   /* parsing one search range */
   uint ind = 1;
   int err = 0;
@@ -458,10 +460,10 @@ parse_get_pdu(struct snmp_proto *p, byte *buf, uint size)
     o_end = (struct oid *) pkt;  // for Get-PDU always null
     pkt += snmp_oid_size(o_end);
 
-    log(L_INFO "sizes o_start %lu o_end %lu", snmp_oid_size(o_start),
+    snmp_log("sizes o_start %lu o_end %lu", snmp_oid_size(o_start),
        snmp_oid_size(o_end));
 
-    log(L_INFO "o_subid: %u o_prefix %u o_include %u ---",
+    snmp_log("o_subid: %u o_prefix %u o_include %u ---",
        o_start->n_subid, o_start->prefix, o_start->include);
 
 
@@ -477,13 +479,13 @@ parse_get_pdu(struct snmp_proto *p, byte *buf, uint size)
     STORE_16(vb_start->pad, 0);  // padding zeroing
     res_pkt += vb_size(vb_start);
 
-    log(L_INFO " vb_size() rpkt %p %u", res_pkt, res_pkt - res);
+    snmp_log(" vb_size() rpkt %p %u", res_pkt, res_pkt - res);
 
     STORE_PTR(res_pkt, 0x1234ABCD);
 
-    log(L_INFO " STORE_PTR int-value rpkt %p %u", res_pkt, res_pkt - res);
+    snmp_log(" STORE_PTR int-value rpkt %p %u", res_pkt, res_pkt - res);
     res_pkt += 4;
-    log(L_INFO " shift rpkt %p %u", res_pkt, res_pkt - res);
+    snmp_log(" shift rpkt %p %u", res_pkt, res_pkt - res);
     */
     ind++;
   }
@@ -494,19 +496,19 @@ parse_get_pdu(struct snmp_proto *p, byte *buf, uint size)
   if (err)
     response_err_ind(res, err, ind);
 
-  log(L_INFO "res->payload %u (loaded) %u, trying to send: %u",
+  snmp_log("res->payload %u (loaded) %u, trying to send: %u",
     rh->payload, LOAD(rh->payload, rh->flags & AGENTX_NETWORK_BYTE_ORDER),
     res_pkt - res + 4);
 
   int ret = sk_send(sk, res_pkt - res);
-  log(L_INFO "message sent");
+  snmp_log("message sent");
 
   if (ret == 0)
-    log(L_INFO "sk_send sleep");
+    snmp_log("sk_send sleep");
   else if (ret < 0)
-    log(L_INFO "sk_send err no: %d", ret);
+    snmp_log("sk_send err no: %d", ret);
   else
-    log(L_INFO "sk_send OK !!");
+    snmp_log("sk_send OK !!");
 
   return 1;
 }
@@ -531,11 +533,11 @@ static byte *
 snmp_get_next(struct snmp_proto *p, struct oid *o_start, struct oid *o_end,
 byte *pkt, uint rsize, uint contid, u8 mib_class, int byte_ord)
 {
-  log(L_INFO "type GetNext-PDU");
+  snmp_log("type GetNext-PDU");
   struct oid *o_copy;
   o_copy = search_mib(p, o_start, o_end, NULL, mib_class, contid);
 
-  log(L_INFO "search result");
+  snmp_log("search result");
   snmp_oid_dump(o_copy);
 
   struct snmp_error error = (struct snmp_error) {
@@ -564,14 +566,14 @@ byte *pkt, uint rsize, uint contid, u8 mib_class, int byte_ord)
     vb->type = AGENTX_NO_SUCH_OBJECT;
   }
 
-  log(L_INFO "over HERE ");
+  snmp_log("over HERE ");
   return pkt;
 }
 
 static byte *
 snmp_get_bulk(struct snmp_proto *p, struct oid *o_start, struct oid *o_end, byte *pkt, uint size, struct agentx_bulk_state *state, uint contid, int byte_ord)
 {
-  log(L_INFO "type GetBulk-PDU");
+  snmp_log("type GetBulk-PDU");
 
   u8 mib_class = get_mib_class(o_start);
 
@@ -634,7 +636,7 @@ snmp_get_bulk(struct snmp_proto *p, struct oid *o_start, struct oid *o_end, byte
 static uint
 parse_gets_pdu(struct snmp_proto *p, byte *req, uint size)
 {
-  log(L_INFO "parse_gets_pdu");
+  snmp_log("parse_gets_pdu");
 
   sock *sk = p->sock;
   byte *res_pkt, *res = sk->tbuf;
@@ -645,7 +647,7 @@ parse_gets_pdu(struct snmp_proto *p, byte *req, uint size)
 
   struct agentx_header *h = (void *) req;
   ADVANCE(req, size, AGENTX_HEADER_SIZE);
-  log(L_INFO "advancing %p cause header", req);
+  snmp_log("advancing %p cause header", req);
 
   byte *pkt = req;
 
@@ -687,7 +689,7 @@ parse_gets_pdu(struct snmp_proto *p, byte *req, uint size)
     /* advertised size of oid is greater then size of message */
     if (snmp_oid_size(o_start_b) > size || snmp_oid_size(o_end_b) > size)
     {
-      log(L_INFO "too big o_start or o_end");
+      snmp_log("too big o_start or o_end");
       err = -1;  /* parse error too big n_subid (greater than message) */
       continue;
     }
@@ -704,12 +706,12 @@ parse_gets_pdu(struct snmp_proto *p, byte *req, uint size)
 
     u8 mib_class = get_mib_class(o_start);
 
-    log(L_INFO "get mib_class () %d -> next pdu parsing ... ", mib_class);
+    snmp_log("get mib_class () %d -> next pdu parsing ... ", mib_class);
 
     switch (h->type)
     {
       case AGENTX_GET_PDU:
-       log(L_INFO "type Get-PDU");
+       snmp_log("type Get-PDU");
 
        struct snmp_error error = (struct snmp_error) {
          .oid = o_start,
@@ -733,7 +735,7 @@ parse_gets_pdu(struct snmp_proto *p, byte *req, uint size)
       // REMOVE ME
       #if 0
       {
-       log(L_INFO "type GetBulk-PDU");
+       snmp_log("type GetBulk-PDU");
 
        struct oid  *o_curr = NULL;
        /* TODO add res packet size limiting logic */
@@ -748,7 +750,7 @@ parse_gets_pdu(struct snmp_proto *p, byte *req, uint size)
        /* no item found */
        if (res_pkt == res + sizeof(struct agentx_response))
        {
-         log(L_INFO "no item found ");
+         snmp_log("no item found ");
          err = -2;
          continue;
        }
@@ -779,15 +781,15 @@ parse_gets_pdu(struct snmp_proto *p, byte *req, uint size)
       break;
   }
 
-  log(L_INFO " pasting size");
+  snmp_log(" pasting size");
   struct agentx_header *rh = (void *) res;
   SNMP_UPDATE(rh, snmp_pkt_len(res, res_pkt));
 
-  log(L_INFO "%p %lu", p->sock->ttx, res_pkt - res);
-  log(L_INFO "%p %p", res_pkt, res);
+  snmp_log("%p %lu", p->sock->ttx, res_pkt - res);
+  snmp_log("%p %p", res_pkt, res);
 
   for (int i = 0; i < res_pkt - res; i++)
-    log(L_INFO "%p: %02X", res + i, *(res + i));
+    snmp_log("%p: %02X", res + i, *(res + i));
 
   return res_pkt - res;
 }
@@ -795,7 +797,7 @@ parse_gets_pdu(struct snmp_proto *p, byte *req, uint size)
 void
 snmp_start_subagent(struct snmp_proto *p)
 {
-  log(L_INFO "snmp_start_subagent() starting subagent");
+  snmp_log("snmp_start_subagent() starting subagent");
 
   /* blank oid means unsupported */
   struct oid *o = mb_allocz(p->p.pool, sizeof(struct oid));
@@ -806,7 +808,7 @@ snmp_start_subagent(struct snmp_proto *p)
 void
 snmp_stop_subagent(struct snmp_proto *p)
 {
-  log(L_INFO "snmp_stop_subagent()");
+  snmp_log("snmp_stop_subagent()");
   sock *sk = p->sock;
 
   if (p->state == SNMP_CONN)
@@ -830,7 +832,7 @@ oid_prefix(struct oid *o, u32 *prefix, uint len)
 int
 snmp_rx(sock *sk, uint size)
 {
-  log(L_INFO "snmp_rx()");
+  snmp_log("snmp_rx()");
   struct snmp_proto *p = sk->data;
   byte *pkt = sk->rbuf;
 
@@ -856,7 +858,7 @@ snmp_ping(struct snmp_proto *p)
 
   if (size > AGENTX_HEADER_SIZE)
   {
-    log(L_INFO "ping_pdu()");
+    snmp_log("ping_pdu()");
     struct agentx_header *h;
     log("before dead %p", pkt );
     SNMP_CREATE(pkt, struct agentx_header, h);
@@ -867,15 +869,15 @@ snmp_ping(struct snmp_proto *p)
     int ret = sk_send(sk, AGENTX_HEADER_SIZE);
 
     if (ret == 0)
-      log(L_INFO "sk_send sleep");
+      snmp_log("sk_send sleep");
     else if (ret < 0)
-      log(L_INFO "sk_send err %d", ret);
+      snmp_log("sk_send err %d", ret);
     else
       log("sk_send ok ! !");
   }
 
   else
-    log(L_INFO "ping_pdu() insufficient size");
+    snmp_log("ping_pdu() insufficient size");
 }
 
 
@@ -986,7 +988,7 @@ has_inet_prefix(struct oid *o)
 static struct oid *
 search_mib(struct snmp_proto *p, struct oid *o_start, struct oid *o_end, struct oid *o_curr, u8 mib_class, uint contid UNUSED)
 {
-  log(L_INFO "search_mib()");
+  snmp_log("search_mib()");
 
   if (!o_start)
     return NULL;
@@ -1287,7 +1289,7 @@ find_ospf_record(struct snmp_proto *p, struct oid *o, byte *buf, uint size)
 static inline byte *
 find_prefixed(struct snmp_proto *p, struct oid *o, byte *buf, uint size, uint contid)
 {
-  log(L_INFO "find_prefixed() - shouldn't be called");
+  snmp_log("find_prefixed() - shouldn't be called");
   struct agentx_varbind *vb = snmp_create_varbind(buf, o);
   buf += snmp_varbind_size(vb);
 
@@ -1301,7 +1303,7 @@ find_prefixed(struct snmp_proto *p, struct oid *o, byte *buf, uint size, uint co
   switch (o->ids[1])
   {
     case SNMP_BGP4_MIB:
-      log(L_INFO "find_prefixed() BGP4");
+      snmp_log("find_prefixed() BGP4");
       //return snmp_bgp_record(p, o, buf, size, contid);
       return buf;
 
@@ -1390,7 +1392,7 @@ find_n_fill(struct snmp_proto *p, struct oid *o, byte *buf, uint size, uint cont
 static byte *snmp_mib_fill(struct snmp_proto *p, struct oid *oid, u8 mib_class,
 byte *buf, uint size, struct snmp_error *error, uint contid, int byte_ord)
 {
-  log(L_INFO "snmp_mib_fill()");
+  snmp_log("snmp_mib_fill()");
 
   if (oid == NULL)
     return buf;
@@ -1425,7 +1427,7 @@ byte *buf, uint size, struct snmp_error *error, uint contid, int byte_ord)
 static byte *
 prepare_response(struct snmp_proto *p, byte *buf, uint size)
 {
-  log(L_INFO "prepare_response()");
+  snmp_log("prepare_response()");
 
   if (size < sizeof(struct agentx_response))
     return NULL;
@@ -1447,7 +1449,7 @@ prepare_response(struct snmp_proto *p, byte *buf, uint size)
 static void
 response_err_ind(byte *buf, uint err, uint ind)
 {
-  log(L_INFO "reponse_err_ind() %u %u", err, ind);
+  snmp_log("reponse_err_ind() %u %u", err, ind);
   struct agentx_response *res = (void *) buf;
 
   res->err = err;
index a4217ebf5144a2ec5ac7e1b00c826c16e52392aa..889cab6557874248dd0474177445af20d5c756b7 100644 (file)
@@ -274,4 +274,7 @@ enum agentx_response_err {
 
 int snmp_rx(sock *sk, uint size);
 
+// debug wrapper
+#define snmp_log(...) log(L_INFO "snmp " __VA_ARGS__)
+
 #endif