]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_packet.c
lib: enforce vrf_name_to_id by returning default_vrf when name is null
[mirror_frr.git] / ospfd / ospf_packet.c
index f1d4a39dba82d06e1262e26ebbd522bd907918dd..3bb3b79a6a728481e75f041f88c5ad58cb786a3c 100644 (file)
@@ -35,7 +35,7 @@
 #include "checksum.h"
 #include "md5.h"
 #include "vrf.h"
-#include "ospf_errors.h"
+#include "lib_errors.h"
 
 #include "ospfd/ospfd.h"
 #include "ospfd/ospf_network.h"
@@ -50,6 +50,7 @@
 #include "ospfd/ospf_spf.h"
 #include "ospfd/ospf_flood.h"
 #include "ospfd/ospf_dump.h"
+#include "ospfd/ospf_errors.h"
 
 /*
  * OSPF Fragmentation / fragmented writes
@@ -232,7 +233,7 @@ void ospf_packet_add(struct ospf_interface *oi, struct ospf_packet *op)
 {
        if (!oi->obuf) {
                flog_err(
-                       OSPF_ERR_PKT_PROCESS,
+                       EC_OSPF_PKT_PROCESS,
                        "ospf_packet_add(interface %s in state %d [%s], packet type %s, "
                        "destination %s) called with NULL obuf, ignoring "
                        "(please report this bug)!\n",
@@ -256,7 +257,7 @@ static void ospf_packet_add_top(struct ospf_interface *oi,
 {
        if (!oi->obuf) {
                flog_err(
-                       OSPF_ERR_PKT_PROCESS,
+                       EC_OSPF_PKT_PROCESS,
                        "ospf_packet_add(interface %s in state %d [%s], packet type %s, "
                        "destination %s) called with NULL obuf, ignoring "
                        "(please report this bug)!\n",
@@ -291,7 +292,7 @@ struct ospf_packet *ospf_packet_dup(struct ospf_packet *op)
 
        if (stream_get_endp(op->s) != op->length)
                /* XXX size_t */
-               zlog_warn(
+               zlog_debug(
                        "ospf_packet_dup stream %lu ospf_packet %u size mismatch",
                        (unsigned long)STREAM_SIZE(op->s), op->length);
 
@@ -341,8 +342,8 @@ static int ospf_check_md5_digest(struct ospf_interface *oi,
        ck = ospf_crypt_key_lookup(OSPF_IF_PARAM(oi, auth_crypt),
                                   ospfh->u.crypt.key_id);
        if (ck == NULL) {
-               zlog_warn("interface %s: ospf_check_md5 no key %d", IF_NAME(oi),
-                         ospfh->u.crypt.key_id);
+               flog_warn(EC_OSPF_MD5, "interface %s: ospf_check_md5 no key %d",
+                         IF_NAME(oi), ospfh->u.crypt.key_id);
                return 0;
        }
 
@@ -351,7 +352,8 @@ static int ospf_check_md5_digest(struct ospf_interface *oi,
 
        if (nbr
            && ntohl(nbr->crypt_seqnum) > ntohl(ospfh->u.crypt.crypt_seqnum)) {
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_MD5,
                        "interface %s: ospf_check_md5 bad sequence %d (expect %d)",
                        IF_NAME(oi), ntohl(ospfh->u.crypt.crypt_seqnum),
                        ntohl(nbr->crypt_seqnum));
@@ -367,7 +369,8 @@ static int ospf_check_md5_digest(struct ospf_interface *oi,
 
        /* compare the two */
        if (memcmp((caddr_t)ospfh + length, digest, OSPF_AUTH_MD5_SIZE)) {
-               zlog_warn("interface %s: ospf_check_md5 checksum mismatch",
+               flog_warn(EC_OSPF_MD5,
+                         "interface %s: ospf_check_md5 checksum mismatch",
                          IF_NAME(oi));
                return 0;
        }
@@ -433,7 +436,8 @@ static int ospf_make_md5_digest(struct ospf_interface *oi,
 
        if (stream_get_endp(op->s) != op->length)
                /* XXX size_t */
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_MD5,
                        "ospf_make_md5_digest: length mismatch stream %lu ospf_packet %u",
                        (unsigned long)stream_get_endp(op->s), op->length);
 
@@ -521,7 +525,7 @@ int ospf_ls_upd_timer(struct thread *thread)
                if (listcount(update) > 0)
                        ospf_ls_upd_send(nbr, update, OSPF_SEND_PACKET_DIRECT,
                                         0);
-               list_delete_and_null(&update);
+               list_delete(&update);
        }
 
        /* Set LS Update retransmission timer. */
@@ -596,7 +600,8 @@ static void ospf_write_frags(int fd, struct ospf_packet *op, struct ip *iph,
                sockopt_iphdrincl_swab_systoh(iph);
 
                if (ret < 0)
-                       zlog_warn(
+                       flog_err(
+                               EC_LIB_SOCKET,
                                "*** ospf_write_frags: sendmsg failed to %s,"
                                " id %d, off %d, len %d, mtu %u failed with %s",
                                inet_ntoa(iph->ip_dst), iph->ip_id, iph->ip_off,
@@ -799,7 +804,8 @@ static int ospf_write(struct thread *thread)
                                iph.ip_len, oi->ifp->name, oi->ifp->mtu);
 
                if (ret < 0)
-                       zlog_warn(
+                       flog_err(
+                               EC_LIB_SOCKET,
                                "*** sendmsg in ospf_write failed to %s, "
                                "id %d, off %d, len %d, interface %s, mtu %u: %s",
                                inet_ntoa(iph.ip_dst), iph.ip_id, iph.ip_off,
@@ -869,11 +875,9 @@ static int ospf_write(struct thread *thread)
        }
 
        /* If packets still remain in queue, call write thread. */
-       if (!list_isempty(ospf->oi_write_q)) {
-               ospf->t_write = NULL;
+       if (!list_isempty(ospf->oi_write_q))
                thread_add_write(master, ospf_write, ospf, ospf->fd,
                                 &ospf->t_write);
-       }
 
        return 0;
 }
@@ -915,7 +919,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
        if (oi->type != OSPF_IFTYPE_POINTOPOINT
            && oi->type != OSPF_IFTYPE_VIRTUALLINK)
                if (oi->address->prefixlen != p.prefixlen) {
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_PACKET,
                                "Packet %s [Hello:RECV]: NetworkMask mismatch on %s (configured prefix length is %d, but hello packet indicates %d).",
                                inet_ntoa(ospfh->router_id), IF_NAME(oi),
                                (int)oi->address->prefixlen, (int)p.prefixlen);
@@ -924,11 +929,12 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
 
        /* Compare Router Dead Interval. */
        if (OSPF_IF_PARAM(oi, v_wait) != ntohl(hello->dead_interval)) {
-               zlog_warn(
-                       "Packet %s [Hello:RECV]: RouterDeadInterval mismatch "
-                       "(expected %u, but received %u).",
-                       inet_ntoa(ospfh->router_id), OSPF_IF_PARAM(oi, v_wait),
-                       ntohl(hello->dead_interval));
+               flog_warn(EC_OSPF_PACKET,
+                         "Packet %s [Hello:RECV]: RouterDeadInterval mismatch "
+                         "(expected %u, but received %u).",
+                         inet_ntoa(ospfh->router_id),
+                         OSPF_IF_PARAM(oi, v_wait),
+                         ntohl(hello->dead_interval));
                return;
        }
 
@@ -936,7 +942,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
        if (OSPF_IF_PARAM(oi, fast_hello) == 0) {
                if (OSPF_IF_PARAM(oi, v_hello)
                    != ntohs(hello->hello_interval)) {
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_PACKET,
                                "Packet %s [Hello:RECV]: HelloInterval mismatch "
                                "(expected %u, but received %u).",
                                inet_ntoa(ospfh->router_id),
@@ -961,7 +968,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
                 * Drop this Hello packet not to establish neighbor
                 * relationship.
                 */
-               zlog_warn("Packet %s [Hello:RECV]: T-bit on, drop it.",
+               flog_warn(EC_OSPF_PACKET,
+                         "Packet %s [Hello:RECV]: T-bit on, drop it.",
                          inet_ntoa(ospfh->router_id));
                return;
        }
@@ -973,7 +981,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
                 * This router does know the correct usage of O-bit
                 * the bit should be set in DD packet only.
                 */
-               zlog_warn("Packet %s [Hello:RECV]: O-bit abuse?",
+               flog_warn(EC_OSPF_PACKET,
+                         "Packet %s [Hello:RECV]: O-bit abuse?",
                          inet_ntoa(ospfh->router_id));
 #ifdef STRICT_OBIT_USAGE_CHECK
                return; /* Reject this packet. */
@@ -989,7 +998,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
                      && CHECK_FLAG(hello->options, OSPF_OPTION_NP)
                      && !CHECK_FLAG(OPTIONS(oi), OSPF_OPTION_E)
                      && !CHECK_FLAG(hello->options, OSPF_OPTION_E))) {
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_PACKET,
                                "NSSA-Packet-%s[Hello:RECV]: my options: %x, his options %x",
                                inet_ntoa(ospfh->router_id), OPTIONS(oi),
                                hello->options);
@@ -1006,7 +1016,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
                   Packet's Options field should be ignored. */
                if (CHECK_FLAG(OPTIONS(oi), OSPF_OPTION_E)
                    != CHECK_FLAG(hello->options, OSPF_OPTION_E)) {
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_PACKET,
                        "Packet %s [Hello:RECV]: my options: %x, his options %x",
                        inet_ntoa(ospfh->router_id), OPTIONS(oi),
                        hello->options);
@@ -1123,7 +1134,8 @@ static void ospf_db_desc_proc(struct stream *s, struct ospf_interface *oi,
 
                /* Unknown LS type. */
                if (lsah->type < OSPF_MIN_LSA || lsah->type >= OSPF_MAX_LSA) {
-                       zlog_warn("Packet [DD:RECV]: Unknown LS type %d.",
+                       flog_warn(EC_OSPF_PACKET,
+                                 "Packet [DD:RECV]: Unknown LS type %d.",
                                  lsah->type);
                        OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_SeqNumberMismatch);
                        return;
@@ -1131,7 +1143,8 @@ static void ospf_db_desc_proc(struct stream *s, struct ospf_interface *oi,
 
                if (IS_OPAQUE_LSA(lsah->type)
                    && !CHECK_FLAG(nbr->options, OSPF_OPTION_O)) {
-                       zlog_warn("LSA[Type%d:%s]: Opaque capability mismatch?",
+                       flog_warn(EC_OSPF_PACKET,
+                                 "LSA[Type%d:%s]: Opaque capability mismatch?",
                                  lsah->type, inet_ntoa(lsah->id));
                        OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_SeqNumberMismatch);
                        return;
@@ -1144,7 +1157,8 @@ static void ospf_db_desc_proc(struct stream *s, struct ospf_interface *oi,
                           but
                           allow if from NSSA. */
                        if (oi->area->external_routing == OSPF_AREA_STUB) {
-                               zlog_warn(
+                               flog_warn(
+                                       EC_OSPF_PACKET,
                                        "Packet [DD:RECV]: LSA[Type%d:%s] from %s area.",
                                        lsah->type, inet_ntoa(lsah->id),
                                        (oi->area->external_routing
@@ -1271,7 +1285,7 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
 
        nbr = ospf_nbr_lookup(oi, iph, ospfh);
        if (nbr == NULL) {
-               zlog_warn("Packet[DD]: Unknown Neighbor %s",
+               flog_warn(EC_OSPF_PACKET, "Packet[DD]: Unknown Neighbor %s",
                          inet_ntoa(ospfh->router_id));
                return;
        }
@@ -1279,7 +1293,8 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
        /* Check MTU. */
        if ((OSPF_IF_PARAM(oi, mtu_ignore) == 0)
            && (ntohs(dd->mtu) > oi->ifp->mtu)) {
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_PACKET,
                        "Packet[DD]: Neighbor %s MTU %u is larger than [%s]'s MTU %u",
                        inet_ntoa(nbr->router_id), ntohs(dd->mtu), IF_NAME(oi),
                        oi->ifp->mtu);
@@ -1318,7 +1333,7 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
                 * In Hello protocol, optional capability must have checked
                 * to prevent this T-bit enabled router be my neighbor.
                 */
-               zlog_warn("Packet[DD]: Neighbor %s: T-bit on?",
+               flog_warn(EC_OSPF_PACKET, "Packet[DD]: Neighbor %s: T-bit on?",
                          inet_ntoa(nbr->router_id));
                return;
        }
@@ -1342,7 +1357,8 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
        case NSM_Down:
        case NSM_Attempt:
        case NSM_TwoWay:
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_PACKET,
                        "Packet[DD]: Neighbor %s state is %s, packet discarded.",
                        inet_ntoa(nbr->router_id),
                        lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
@@ -1396,7 +1412,8 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
                        /* Reset I, leaving MS */
                        UNSET_FLAG(nbr->dd_flags, OSPF_DD_FLAG_I);
                } else {
-                       zlog_warn("Packet[DD]: Neighbor %s Negotiation fails.",
+                       flog_warn(EC_OSPF_PACKET,
+                                 "Packet[DD]: Neighbor %s Negotiation fails.",
                                  inet_ntoa(nbr->router_id));
                        break;
                }
@@ -1416,10 +1433,9 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
                        if (!CHECK_FLAG(nbr->options, OSPF_OPTION_O)
                            && IPV4_ADDR_SAME(&DR(oi),
                                              &nbr->address.u.prefix4)) {
-                               zlog_warn(
-                                       "DR-neighbor[%s] is NOT opaque-capable; "
-                                       "Opaque-LSAs cannot be reliably advertised "
-                                       "in this network.",
+                               flog_warn(
+                                       EC_OSPF_PACKET,
+                                       "DR-neighbor[%s] is NOT opaque-capable; Opaque-LSAs cannot be reliably advertised in this network.",
                                        inet_ntoa(nbr->router_id));
                                /* This situation is undesirable, but not a real
                                 * error. */
@@ -1454,7 +1470,8 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
                /* Check Master/Slave bit mismatch */
                if (IS_SET_DD_MS(dd->flags)
                    != IS_SET_DD_MS(nbr->last_recv.flags)) {
-                       zlog_warn("Packet[DD]: Neighbor %s MS-bit mismatch.",
+                       flog_warn(EC_OSPF_PACKET,
+                                 "Packet[DD]: Neighbor %s MS-bit mismatch.",
                                  inet_ntoa(nbr->router_id));
                        OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_SeqNumberMismatch);
                        if (IS_DEBUG_OSPF_EVENT)
@@ -1478,7 +1495,8 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
                        /* Save the new options for debugging */
                        nbr->options = dd->options;
 #endif /* ORIGINAL_CODING */
-                       zlog_warn("Packet[DD]: Neighbor %s options mismatch.",
+                       flog_warn(EC_OSPF_PACKET,
+                                 "Packet[DD]: Neighbor %s options mismatch.",
                                  inet_ntoa(nbr->router_id));
                        OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_SeqNumberMismatch);
                        break;
@@ -1489,7 +1507,8 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
                     && ntohl(dd->dd_seqnum) != nbr->dd_seqnum)
                    || (!IS_SET_DD_MS(nbr->dd_flags)
                        && ntohl(dd->dd_seqnum) != nbr->dd_seqnum + 1)) {
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_PACKET,
                                "Packet[DD]: Neighbor %s sequence number mismatch.",
                                inet_ntoa(nbr->router_id));
                        OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_SeqNumberMismatch);
@@ -1539,7 +1558,8 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
                OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_SeqNumberMismatch);
                break;
        default:
-               zlog_warn("Packet[DD]: Neighbor %s NSM illegal status %u.",
+               flog_warn(EC_OSPF_PACKET,
+                         "Packet[DD]: Neighbor %s NSM illegal status %u.",
                          inet_ntoa(nbr->router_id), nbr->state);
                break;
        }
@@ -1565,7 +1585,8 @@ static void ospf_ls_req(struct ip *iph, struct ospf_header *ospfh,
 
        nbr = ospf_nbr_lookup(oi, iph, ospfh);
        if (nbr == NULL) {
-               zlog_warn("Link State Request: Unknown Neighbor %s.",
+               flog_warn(EC_OSPF_PACKET,
+                         "Link State Request: Unknown Neighbor %s.",
                          inet_ntoa(ospfh->router_id));
                return;
        }
@@ -1576,9 +1597,9 @@ static void ospf_ls_req(struct ip *iph, struct ospf_header *ospfh,
        /* Neighbor State should be Exchange or later. */
        if (nbr->state != NSM_Exchange && nbr->state != NSM_Loading
            && nbr->state != NSM_Full) {
-               zlog_warn(
-                       "Link State Request received from %s: "
-                       "Neighbor state is %s, packet discarded.",
+               flog_warn(
+                       EC_OSPF_PACKET,
+                       "Link State Request received from %s: Neighbor state is %s, packet discarded.",
                        inet_ntoa(ospfh->router_id),
                        lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
                return;
@@ -1597,7 +1618,7 @@ static void ospf_ls_req(struct ip *iph, struct ospf_header *ospfh,
                /* Verify LSA type. */
                if (ls_type < OSPF_MIN_LSA || ls_type >= OSPF_MAX_LSA) {
                        OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_BadLSReq);
-                       list_delete_and_null(&ls_upd);
+                       list_delete(&ls_upd);
                        return;
                }
 
@@ -1606,7 +1627,7 @@ static void ospf_ls_req(struct ip *iph, struct ospf_header *ospfh,
                                       adv_router);
                if (find == NULL) {
                        OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_BadLSReq);
-                       list_delete_and_null(&ls_upd);
+                       list_delete(&ls_upd);
                        return;
                }
 
@@ -1641,9 +1662,9 @@ static void ospf_ls_req(struct ip *iph, struct ospf_header *ospfh,
                        ospf_ls_upd_send(nbr, ls_upd, OSPF_SEND_PACKET_INDIRECT,
                                         0);
 
-               list_delete_and_null(&ls_upd);
+               list_delete(&ls_upd);
        } else
-               list_delete_and_null(&ls_upd);
+               list_delete(&ls_upd);
 }
 
 /* Get the list of LSAs from Link State Update packet.
@@ -1669,7 +1690,8 @@ static struct list *ospf_ls_upd_list_lsa(struct ospf_neighbor *nbr,
                length = ntohs(lsah->length);
 
                if (length > size) {
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_PACKET,
                                "Link State Update: LSA length exceeds packet size.");
                        break;
                }
@@ -1683,7 +1705,8 @@ static struct list *ospf_ls_upd_list_lsa(struct ospf_neighbor *nbr,
                         * have a better
                         * chance to compress repeated messages in syslog on the
                         * other */
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_PACKET,
                                "Link State Update: LSA checksum error %x/%x, ID=%s from: nbr %s, router ID %s, adv router %s",
                                sum, lsah->checksum, inet_ntoa(lsah->id),
                                inet_ntoa(nbr->src), inet_ntoa(nbr->router_id),
@@ -1693,7 +1716,8 @@ static struct list *ospf_ls_upd_list_lsa(struct ospf_neighbor *nbr,
 
                /* Examine the LSA's LS type. */
                if (lsah->type < OSPF_MIN_LSA || lsah->type >= OSPF_MAX_LSA) {
-                       zlog_warn("Link State Update: Unknown LS type %d",
+                       flog_warn(EC_OSPF_PACKET,
+                                 "Link State Update: Unknown LS type %d",
                                  lsah->type);
                        continue;
                }
@@ -1717,7 +1741,8 @@ static struct list *ospf_ls_upd_list_lsa(struct ospf_neighbor *nbr,
                                 * the bit will be set in Type-9,10,11 LSAs
                                 * only.
                                 */
-                               zlog_warn("LSA[Type%d:%s]: O-bit abuse?",
+                               flog_warn(EC_OSPF_PACKET,
+                                         "LSA[Type%d:%s]: O-bit abuse?",
                                          lsah->type, inet_ntoa(lsah->id));
                                continue;
                        }
@@ -1736,13 +1761,14 @@ static struct list *ospf_ls_upd_list_lsa(struct ospf_neighbor *nbr,
                                continue;
                        }
                } else if (IS_OPAQUE_LSA(lsah->type)) {
-                       zlog_warn("LSA[Type%d:%s]: Opaque capability mismatch?",
+                       flog_warn(EC_OSPF_PACKET,
+                                 "LSA[Type%d:%s]: Opaque capability mismatch?",
                                  lsah->type, inet_ntoa(lsah->id));
                        continue;
                }
 
                /* Create OSPF LSA instance. */
-               lsa = ospf_lsa_new();
+               lsa = ospf_lsa_new_and_data(length);
 
                lsa->vrf_id = oi->ospf->vrf_id;
                /* We may wish to put some error checking if type NSSA comes in
@@ -1761,7 +1787,6 @@ static struct list *ospf_ls_upd_list_lsa(struct ospf_neighbor *nbr,
                        break;
                }
 
-               lsa->data = ospf_lsa_data_new(length);
                memcpy(lsa->data, lsah, length);
 
                if (IS_DEBUG_OSPF_EVENT)
@@ -1784,7 +1809,7 @@ static void ospf_upd_list_clean(struct list *lsas)
        for (ALL_LIST_ELEMENTS(lsas, node, nnode, lsa))
                ospf_lsa_discard(lsa);
 
-       list_delete_and_null(&lsas);
+       list_delete(&lsas);
 }
 
 /* OSPF Link State Update message read -- RFC2328 Section 13. */
@@ -1807,7 +1832,8 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
        /* Check neighbor. */
        nbr = ospf_nbr_lookup(oi, iph, ospfh);
        if (nbr == NULL) {
-               zlog_warn("Link State Update: Unknown Neighbor %s on int: %s",
+               flog_warn(EC_OSPF_PACKET,
+                         "Link State Update: Unknown Neighbor %s on int: %s",
                          inet_ntoa(ospfh->router_id), IF_NAME(oi));
                return;
        }
@@ -1918,18 +1944,18 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
                                char buf2[INET_ADDRSTRLEN];
                                char buf3[INET_ADDRSTRLEN];
 
-                               flog_err(OSPF_ERR_ROUTER_LSA_MISMATCH,
-                                         "Incoming Router-LSA from %s with "
-                                         "Adv-ID[%s] != LS-ID[%s]",
-                                         inet_ntop(AF_INET, &ospfh->router_id,
-                                                   buf1, INET_ADDRSTRLEN),
-                                         inet_ntop(AF_INET, &lsa->data->id,
-                                                   buf2, INET_ADDRSTRLEN),
-                                         inet_ntop(AF_INET,
-                                                   &lsa->data->adv_router,
-                                                   buf3, INET_ADDRSTRLEN));
+                               flog_err(EC_OSPF_ROUTER_LSA_MISMATCH,
+                                        "Incoming Router-LSA from %s with "
+                                        "Adv-ID[%s] != LS-ID[%s]",
+                                        inet_ntop(AF_INET, &ospfh->router_id,
+                                                  buf1, INET_ADDRSTRLEN),
+                                        inet_ntop(AF_INET, &lsa->data->id,
+                                                  buf2, INET_ADDRSTRLEN),
+                                        inet_ntop(AF_INET,
+                                                  &lsa->data->adv_router, buf3,
+                                                  INET_ADDRSTRLEN));
                                flog_err(
-                                       OSPF_ERR_DOMAIN_CORRUPT,
+                                       EC_OSPF_DOMAIN_CORRUPT,
                                        "OSPF domain compromised by attack or corruption. "
                                        "Verify correct operation of -ALL- OSPF routers.");
                                DISCARD_LSA(lsa, 0);
@@ -1972,7 +1998,7 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
                         * Just send an LSAck message to cease retransmission.
                         */
                        if (IS_LSA_MAXAGE(lsa)) {
-                               zlog_warn("LSA[%s]: Boomerang effect?",
+                               zlog_info("LSA[%s]: Boomerang effect?",
                                          dump_lsa_key(lsa));
                                ospf_ls_ack_send(nbr, lsa);
                                ospf_lsa_discard(lsa);
@@ -2088,7 +2114,8 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
 
                if (ospf_ls_request_lookup(nbr, lsa)) {
                        OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_BadLSReq);
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_PACKET,
                                "LSA[%s] instance exists on Link state request list",
                                dump_lsa_key(lsa));
 
@@ -2186,7 +2213,7 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
 #undef DISCARD_LSA
 
        assert(listcount(lsas) == 0);
-       list_delete_and_null(&lsas);
+       list_delete(&lsas);
 }
 
 /* OSPF Link State Acknowledgment message read -- RFC2328 Section 13.7. */
@@ -2201,7 +2228,8 @@ static void ospf_ls_ack(struct ip *iph, struct ospf_header *ospfh,
 
        nbr = ospf_nbr_lookup(oi, iph, ospfh);
        if (nbr == NULL) {
-               zlog_warn("Link State Acknowledgment: Unknown Neighbor %s.",
+               flog_warn(EC_OSPF_PACKET,
+                         "Link State Acknowledgment: Unknown Neighbor %s.",
                          inet_ntoa(ospfh->router_id));
                return;
        }
@@ -2271,12 +2299,14 @@ static struct stream *ospf_recv_packet(struct ospf *ospf, int fd,
 
        ret = stream_recvmsg(ibuf, fd, &msgh, 0, OSPF_MAX_PACKET_SIZE + 1);
        if (ret < 0) {
-               zlog_warn("stream_recvmsg failed: %s", safe_strerror(errno));
+               flog_warn(EC_OSPF_PACKET, "stream_recvmsg failed: %s",
+                         safe_strerror(errno));
                return NULL;
        }
        if ((unsigned int)ret < sizeof(iph)) /* ret must be > 0 now */
        {
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_PACKET,
                        "ospf_recv_packet: discarding runt packet of length %d "
                        "(ip header size is %u)",
                        ret, (unsigned int)sizeof(iph));
@@ -2322,7 +2352,8 @@ static struct stream *ospf_recv_packet(struct ospf *ospf, int fd,
        *ifp = if_lookup_by_index(ifindex, ospf->vrf_id);
 
        if (ret != ip_len) {
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_PACKET,
                        "ospf_recv_packet read length mismatch: ip_len is %d, "
                        "but recvmsg returned %d",
                        ip_len, ret);
@@ -2428,7 +2459,8 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
        case OSPF_AUTH_NULL: /* RFC2328 D.5.1 */
                if (OSPF_AUTH_NULL != (iface_auth_type = ospf_auth_type(oi))) {
                        if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
-                               zlog_warn(
+                               flog_warn(
+                                       EC_OSPF_PACKET,
                                        "interface %s: auth-type mismatch, local %s, rcvd Null",
                                        IF_NAME(oi),
                                        lookup_msg(ospf_auth_type_str,
@@ -2437,7 +2469,8 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
                }
                if (!ospf_check_sum(ospfh)) {
                        if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
-                               zlog_warn(
+                               flog_warn(
+                                       EC_OSPF_PACKET,
                                        "interface %s: Null auth OK, but checksum error, Router-ID %s",
                                        IF_NAME(oi),
                                        inet_ntoa(ospfh->router_id));
@@ -2448,7 +2481,8 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
                if (OSPF_AUTH_SIMPLE
                    != (iface_auth_type = ospf_auth_type(oi))) {
                        if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
-                               zlog_warn(
+                               flog_warn(
+                                       EC_OSPF_PACKET,
                                        "interface %s: auth-type mismatch, local %s, rcvd Simple",
                                        IF_NAME(oi),
                                        lookup_msg(ospf_auth_type_str,
@@ -2458,13 +2492,15 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
                if (memcmp(OSPF_IF_PARAM(oi, auth_simple), ospfh->u.auth_data,
                           OSPF_AUTH_SIMPLE_SIZE)) {
                        if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
-                               zlog_warn("interface %s: Simple auth failed",
+                               flog_warn(EC_OSPF_PACKET,
+                                         "interface %s: Simple auth failed",
                                          IF_NAME(oi));
                        return 0;
                }
                if (!ospf_check_sum(ospfh)) {
                        if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
-                               zlog_warn(
+                               flog_warn(
+                                       EC_OSPF_PACKET,
                                        "interface %s: Simple auth OK, checksum error, Router-ID %s",
                                        IF_NAME(oi),
                                        inet_ntoa(ospfh->router_id));
@@ -2475,7 +2511,8 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
                if (OSPF_AUTH_CRYPTOGRAPHIC
                    != (iface_auth_type = ospf_auth_type(oi))) {
                        if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
-                               zlog_warn(
+                               flog_warn(
+                                       EC_OSPF_PACKET,
                                        "interface %s: auth-type mismatch, local %s, rcvd Cryptographic",
                                        IF_NAME(oi),
                                        lookup_msg(ospf_auth_type_str,
@@ -2484,7 +2521,8 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
                }
                if (ospfh->checksum) {
                        if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
-                               zlog_warn(
+                               flog_warn(
+                                       EC_OSPF_PACKET,
                                        "interface %s: OSPF header checksum is not 0",
                                        IF_NAME(oi));
                        return 0;
@@ -2499,14 +2537,16 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
                       bug? */
                    !ospf_check_md5_digest(oi, ospfh)) {
                        if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
-                               zlog_warn("interface %s: MD5 auth failed",
+                               flog_warn(EC_OSPF_MD5,
+                                         "interface %s: MD5 auth failed",
                                          IF_NAME(oi));
                        return 0;
                }
                return 1;
        default:
                if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_PACKET,
                                "interface %s: invalid packet auth-type (%02x)",
                                IF_NAME(oi), pkt_auth_type);
                return 0;
@@ -2855,14 +2895,16 @@ static int ospf_verify_header(struct stream *ibuf, struct ospf_interface *oi,
 {
        /* Check Area ID. */
        if (!ospf_check_area_id(oi, ospfh)) {
-               zlog_warn("interface %s: ospf_read invalid Area ID %s.",
+               flog_warn(EC_OSPF_PACKET,
+                         "interface %s: ospf_read invalid Area ID %s.",
                          IF_NAME(oi), inet_ntoa(ospfh->area_id));
                return -1;
        }
 
        /* Check network mask, Silently discarded. */
        if (!ospf_check_network_mask(oi, iph->ip_src)) {
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_PACKET,
                        "interface %s: ospf_read network address is not same [%s]",
                        IF_NAME(oi), inet_ntoa(iph->ip_src));
                return -1;
@@ -3007,12 +3049,14 @@ int ospf_read(struct thread *thread)
         */
        else if (oi->ifp != ifp) {
                if (IS_DEBUG_OSPF_EVENT)
-                       zlog_warn("Packet from [%s] received on wrong link %s",
+                       flog_warn(EC_OSPF_PACKET,
+                                 "Packet from [%s] received on wrong link %s",
                                  inet_ntoa(iph->ip_src), ifp->name);
                return 0;
        } else if (oi->state == ISM_Down) {
                char buf[2][INET_ADDRSTRLEN];
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_PACKET,
                        "Ignoring packet from %s to %s received on interface that is "
                        "down [%s]; interface flags are %s",
                        inet_ntop(AF_INET, &iph->ip_src, buf[0],
@@ -3037,7 +3081,8 @@ int ospf_read(struct thread *thread)
         */
        if (iph->ip_dst.s_addr == htonl(OSPF_ALLDROUTERS)
            && (oi->state != ISM_DR && oi->state != ISM_Backup)) {
-               zlog_warn(
+               flog_warn(
+                       EC_OSPF_PACKET,
                        "Dropping packet for AllDRouters from [%s] via [%s] (ISM: %s)",
                        inet_ntoa(iph->ip_src), IF_NAME(oi),
                        lookup_msg(ospf_ism_state_msg, oi->state, NULL));
@@ -3100,7 +3145,8 @@ int ospf_read(struct thread *thread)
                ospf_ls_ack(iph, ospfh, ibuf, oi, length);
                break;
        default:
-               zlog_warn("interface %s: OSPF packet header type %d is illegal",
+               flog_warn(EC_OSPF_PACKET,
+                         "interface %s: OSPF packet header type %d is illegal",
                          IF_NAME(oi), ospfh->type);
                break;
        }
@@ -3322,7 +3368,7 @@ static int ospf_make_db_desc(struct ospf_interface *oi,
                                if (IS_OPAQUE_LSA(lsa->data->type)
                                    && (!CHECK_FLAG(options, OSPF_OPTION_O))) {
                                        /* Suppress advertising
-                                        * opaque-informations. */
+                                        * opaque-information. */
                                        /* Remove LSA from DB summary list. */
                                        ospf_lsdb_delete(lsdb, lsa);
                                        continue;
@@ -3807,7 +3853,7 @@ void ospf_ls_upd_send_lsa(struct ospf_neighbor *nbr, struct ospf_lsa *lsa,
        else
                ospf_ls_upd_send(nbr, update, flag, 0);
 
-       list_delete_and_null(&update);
+       list_delete(&update);
 }
 
 /* Determine size for packet. Must be at least big enough to accomodate next
@@ -3831,7 +3877,8 @@ static struct ospf_packet *ospf_ls_upd_packet_new(struct list *update,
        if ((OSPF_LS_UPD_MIN_SIZE + ntohs(lsa->data->length))
            > ospf_packet_max(oi)) {
                if (!warned) {
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_LARGE_LSA,
                                "ospf_ls_upd_packet_new: oversized LSA encountered!"
                                "will need to fragment. Not optimal. Try divide up"
                                " your network with areas. Use 'debug ospf packet send'"
@@ -3859,12 +3906,12 @@ static struct ospf_packet *ospf_ls_upd_packet_new(struct list *update,
                size = oi->ifp->mtu;
 
        if (size > OSPF_MAX_PACKET_SIZE) {
-               zlog_warn(
-                       "ospf_ls_upd_packet_new: oversized LSA id:%s too big,"
-                       " %d bytes, packet size %ld, dropping it completely."
-                       " OSPF routing is broken!",
-                       inet_ntoa(lsa->data->id), ntohs(lsa->data->length),
-                       (long int)size);
+               flog_warn(EC_OSPF_LARGE_LSA,
+                         "ospf_ls_upd_packet_new: oversized LSA id:%s too big,"
+                         " %d bytes, packet size %ld, dropping it completely."
+                         " OSPF routing is broken!",
+                         inet_ntoa(lsa->data->id), ntohs(lsa->data->length),
+                         (long int)size);
                list_delete_node(update, ln);
                return NULL;
        }
@@ -3967,7 +4014,7 @@ static int ospf_ls_upd_send_queue_event(struct thread *thread)
 
                /* list might not be empty. */
                if (listcount(update) == 0) {
-                       list_delete_and_null((struct list **)&rn->info);
+                       list_delete((struct list **)&rn->info);
                        route_unlock_node(rn);
                } else
                        again = 1;
@@ -4020,10 +4067,12 @@ void ospf_ls_upd_send(struct ospf_neighbor *nbr, struct list *update, int flag,
 
        if (oi->type == OSPF_IFTYPE_NBMA) {
                if (flag == OSPF_SEND_PACKET_INDIRECT)
-                       zlog_warn(
+                       flog_warn(
+                               EC_OSPF_PACKET,
                                "* LS-Update is directly sent on NBMA network.");
                if (IPV4_ADDR_SAME(&oi->address->u.prefix4, &p.prefix))
-                       zlog_warn("* LS-Update is sent to myself.");
+                       flog_warn(EC_OSPF_PACKET,
+                                 "* LS-Update is sent to myself.");
        }
 
        rn = route_node_get(oi->ls_upd_queue, (struct prefix *)&p);
@@ -4038,7 +4087,7 @@ void ospf_ls_upd_send(struct ospf_neighbor *nbr, struct list *update, int flag,
                             ospf_lsa_lock(lsa)); /* oi->ls_upd_queue */
        if (send_lsupd_now) {
                struct list *send_update_list;
-               struct route_node *rn, *rnext;
+               struct route_node *rnext;
 
                for (rn = route_top(oi->ls_upd_queue); rn; rn = rnext) {
                        rnext = route_next(rn);