]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_api.c
zebra: Allow ns delete to happen after under/over flow checks
[mirror_frr.git] / ospfd / ospf_api.c
index 10570f4e62f85cc7240fa29946176723a362ffad..b1175a2f68cc3f7e080fff2048a7a3945b439c49 100644 (file)
@@ -62,7 +62,7 @@ void api_opaque_lsa_print(struct lsa_header *data)
 {
        struct opaque_lsa {
                struct lsa_header header;
-               u_char mydata[];
+               uint8_t mydata[];
        };
 
        struct opaque_lsa *olsa;
@@ -87,8 +87,8 @@ void api_opaque_lsa_print(struct lsa_header *data)
  * -----------------------------------------------------------
  */
 
-struct msg *msg_new(u_char msgtype, void *msgbody, u_int32_t seqnum,
-                   u_int16_t msglen)
+struct msg *msg_new(uint8_t msgtype, void *msgbody, uint32_t seqnum,
+                   uint16_t msglen)
 {
        struct msg *new;
 
@@ -131,60 +131,46 @@ const char *ospf_api_typename(int msgtype)
 {
        struct nametab NameTab[] = {
                {
-                       MSG_REGISTER_OPAQUETYPE,
-                       "Register opaque-type",
+                       MSG_REGISTER_OPAQUETYPE, "Register opaque-type",
                },
                {
-                       MSG_UNREGISTER_OPAQUETYPE,
-                       "Unregister opaque-type",
+                       MSG_UNREGISTER_OPAQUETYPE, "Unregister opaque-type",
                },
                {
-                       MSG_REGISTER_EVENT,
-                       "Register event",
+                       MSG_REGISTER_EVENT, "Register event",
                },
                {
-                       MSG_SYNC_LSDB,
-                       "Sync LSDB",
+                       MSG_SYNC_LSDB, "Sync LSDB",
                },
                {
-                       MSG_ORIGINATE_REQUEST,
-                       "Originate request",
+                       MSG_ORIGINATE_REQUEST, "Originate request",
                },
                {
-                       MSG_DELETE_REQUEST,
-                       "Delete request",
+                       MSG_DELETE_REQUEST, "Delete request",
                },
                {
-                       MSG_REPLY,
-                       "Reply",
+                       MSG_REPLY, "Reply",
                },
                {
-                       MSG_READY_NOTIFY,
-                       "Ready notify",
+                       MSG_READY_NOTIFY, "Ready notify",
                },
                {
-                       MSG_LSA_UPDATE_NOTIFY,
-                       "LSA update notify",
+                       MSG_LSA_UPDATE_NOTIFY, "LSA update notify",
                },
                {
-                       MSG_LSA_DELETE_NOTIFY,
-                       "LSA delete notify",
+                       MSG_LSA_DELETE_NOTIFY, "LSA delete notify",
                },
                {
-                       MSG_NEW_IF,
-                       "New interface",
+                       MSG_NEW_IF, "New interface",
                },
                {
-                       MSG_DEL_IF,
-                       "Del interface",
+                       MSG_DEL_IF, "Del interface",
                },
                {
-                       MSG_ISM_CHANGE,
-                       "ISM change",
+                       MSG_ISM_CHANGE, "ISM change",
                },
                {
-                       MSG_NSM_CHANGE,
-                       "NSM change",
+                       MSG_NSM_CHANGE, "NSM change",
                },
        };
 
@@ -205,48 +191,38 @@ const char *ospf_api_errname(int errcode)
 {
        struct nametab NameTab[] = {
                {
-                       OSPF_API_OK,
-                       "OK",
+                       OSPF_API_OK, "OK",
                },
                {
-                       OSPF_API_NOSUCHINTERFACE,
-                       "No such interface",
+                       OSPF_API_NOSUCHINTERFACE, "No such interface",
                },
                {
-                       OSPF_API_NOSUCHAREA,
-                       "No such area",
+                       OSPF_API_NOSUCHAREA, "No such area",
                },
                {
-                       OSPF_API_NOSUCHLSA,
-                       "No such LSA",
+                       OSPF_API_NOSUCHLSA, "No such LSA",
                },
                {
-                       OSPF_API_ILLEGALLSATYPE,
-                       "Illegal LSA type",
+                       OSPF_API_ILLEGALLSATYPE, "Illegal LSA type",
                },
                {
-                       OSPF_API_OPAQUETYPEINUSE,
-                       "Opaque type in use",
+                       OSPF_API_OPAQUETYPEINUSE, "Opaque type in use",
                },
                {
                        OSPF_API_OPAQUETYPENOTREGISTERED,
                        "Opaque type not registered",
                },
                {
-                       OSPF_API_NOTREADY,
-                       "Not ready",
+                       OSPF_API_NOTREADY, "Not ready",
                },
                {
-                       OSPF_API_NOMEMORY,
-                       "No memory",
+                       OSPF_API_NOMEMORY, "No memory",
                },
                {
-                       OSPF_API_ERROR,
-                       "Other error",
+                       OSPF_API_ERROR, "Other error",
                },
                {
-                       OSPF_API_UNDEF,
-                       "Undefined",
+                       OSPF_API_UNDEF, "Undefined",
                },
        };
 
@@ -306,14 +282,14 @@ void msg_free(struct msg *msg)
 
 
 /* Set sequence number of message */
-void msg_set_seq(struct msg *msg, u_int32_t seqnr)
+void msg_set_seq(struct msg *msg, uint32_t seqnr)
 {
        assert(msg);
        msg->hdr.msgseq = htonl(seqnr);
 }
 
 /* Get sequence number of message */
-u_int32_t msg_get_seq(struct msg *msg)
+uint32_t msg_get_seq(struct msg *msg)
 {
        assert(msg);
        return ntohl(msg->hdr.msgseq);
@@ -392,12 +368,12 @@ struct msg *msg_read(int fd)
 {
        struct msg *msg;
        struct apimsghdr hdr;
-       u_char buf[OSPF_API_MAX_MSG_SIZE];
+       uint8_t buf[OSPF_API_MAX_MSG_SIZE];
        int bodylen;
        int rlen;
 
        /* Read message header */
-       rlen = readn(fd, (u_char *)&hdr, sizeof(struct apimsghdr));
+       rlen = readn(fd, (uint8_t *)&hdr, sizeof(struct apimsghdr));
 
        if (rlen < 0) {
                zlog_warn("msg_read: readn %s", safe_strerror(errno));
@@ -442,7 +418,7 @@ struct msg *msg_read(int fd)
 
 int msg_write(int fd, struct msg *msg)
 {
-       u_char buf[OSPF_API_MAX_MSG_SIZE];
+       uint8_t buf[OSPF_API_MAX_MSG_SIZE];
        int l;
        int wlen;
 
@@ -476,8 +452,8 @@ int msg_write(int fd, struct msg *msg)
  * -----------------------------------------------------------
  */
 
-struct msg *new_msg_register_opaque_type(u_int32_t seqnum, u_char ltype,
-                                        u_char otype)
+struct msg *new_msg_register_opaque_type(uint32_t seqnum, uint8_t ltype,
+                                        uint8_t otype)
 {
        struct msg_register_opaque_type rmsg;
 
@@ -489,10 +465,10 @@ struct msg *new_msg_register_opaque_type(u_int32_t seqnum, u_char ltype,
                       sizeof(struct msg_register_opaque_type));
 }
 
-struct msg *new_msg_register_event(u_int32_t seqnum,
+struct msg *new_msg_register_event(uint32_t seqnum,
                                   struct lsa_filter_type *filter)
 {
-       u_char buf[OSPF_API_MAX_MSG_SIZE];
+       uint8_t buf[OSPF_API_MAX_MSG_SIZE];
        struct msg_register_event *emsg;
        unsigned int len;
 
@@ -508,9 +484,9 @@ struct msg *new_msg_register_event(u_int32_t seqnum,
        return msg_new(MSG_REGISTER_EVENT, emsg, seqnum, len);
 }
 
-struct msg *new_msg_sync_lsdb(u_int32_t seqnum, struct lsa_filter_type *filter)
+struct msg *new_msg_sync_lsdb(uint32_t seqnum, struct lsa_filter_type *filter)
 {
-       u_char buf[OSPF_API_MAX_MSG_SIZE];
+       uint8_t buf[OSPF_API_MAX_MSG_SIZE];
        struct msg_sync_lsdb *smsg;
        unsigned int len;
 
@@ -527,33 +503,34 @@ struct msg *new_msg_sync_lsdb(u_int32_t seqnum, struct lsa_filter_type *filter)
 }
 
 
-struct msg *new_msg_originate_request(u_int32_t seqnum, struct in_addr ifaddr,
+struct msg *new_msg_originate_request(uint32_t seqnum, struct in_addr ifaddr,
                                      struct in_addr area_id,
                                      struct lsa_header *data)
 {
        struct msg_originate_request *omsg;
        unsigned int omsglen;
        char buf[OSPF_API_MAX_MSG_SIZE];
+       size_t off_data = offsetof(struct msg_originate_request, data);
+       size_t data_maxs = sizeof(buf) - off_data;
+       struct lsa_header *omsg_data = (struct lsa_header *)&buf[off_data];
 
        omsg = (struct msg_originate_request *)buf;
        omsg->ifaddr = ifaddr;
        omsg->area_id = area_id;
 
        omsglen = ntohs(data->length);
-       if (omsglen
-           > sizeof(buf) - offsetof(struct msg_originate_request, data))
-               omsglen = sizeof(buf)
-                         - offsetof(struct msg_originate_request, data);
-       memcpy(&omsg->data, data, omsglen);
+       if (omsglen > data_maxs)
+               omsglen = data_maxs;
+       memcpy(omsg_data, data, omsglen);
        omsglen += sizeof(struct msg_originate_request)
                   - sizeof(struct lsa_header);
 
        return msg_new(MSG_ORIGINATE_REQUEST, omsg, seqnum, omsglen);
 }
 
-struct msg *new_msg_delete_request(u_int32_t seqnum, struct in_addr area_id,
-                                  u_char lsa_type, u_char opaque_type,
-                                  u_int32_t opaque_id)
+struct msg *new_msg_delete_request(uint32_t seqnum, struct in_addr area_id,
+                                  uint8_t lsa_type, uint8_t opaque_type,
+                                  uint32_t opaque_id)
 {
        struct msg_delete_request dmsg;
        dmsg.area_id = area_id;
@@ -567,7 +544,7 @@ struct msg *new_msg_delete_request(u_int32_t seqnum, struct in_addr area_id,
 }
 
 
-struct msg *new_msg_reply(u_int32_t seqnr, u_char rc)
+struct msg *new_msg_reply(uint32_t seqnr, uint8_t rc)
 {
        struct msg *msg;
        struct msg_reply rmsg;
@@ -581,8 +558,8 @@ struct msg *new_msg_reply(u_int32_t seqnr, u_char rc)
        return msg;
 }
 
-struct msg *new_msg_ready_notify(u_int32_t seqnr, u_char lsa_type,
-                                u_char opaque_type, struct in_addr addr)
+struct msg *new_msg_ready_notify(uint32_t seqnr, uint8_t lsa_type,
+                                uint8_t opaque_type, struct in_addr addr)
 {
        struct msg_ready_notify rmsg;
 
@@ -595,7 +572,7 @@ struct msg *new_msg_ready_notify(u_int32_t seqnr, u_char lsa_type,
                       sizeof(struct msg_ready_notify));
 }
 
-struct msg *new_msg_new_if(u_int32_t seqnr, struct in_addr ifaddr,
+struct msg *new_msg_new_if(uint32_t seqnr, struct in_addr ifaddr,
                           struct in_addr area_id)
 {
        struct msg_new_if nmsg;
@@ -606,7 +583,7 @@ struct msg *new_msg_new_if(u_int32_t seqnr, struct in_addr ifaddr,
        return msg_new(MSG_NEW_IF, &nmsg, seqnr, sizeof(struct msg_new_if));
 }
 
-struct msg *new_msg_del_if(u_int32_t seqnr, struct in_addr ifaddr)
+struct msg *new_msg_del_if(uint32_t seqnr, struct in_addr ifaddr)
 {
        struct msg_del_if dmsg;
 
@@ -615,8 +592,8 @@ struct msg *new_msg_del_if(u_int32_t seqnr, struct in_addr ifaddr)
        return msg_new(MSG_DEL_IF, &dmsg, seqnr, sizeof(struct msg_del_if));
 }
 
-struct msg *new_msg_ism_change(u_int32_t seqnr, struct in_addr ifaddr,
-                              struct in_addr area_id, u_char status)
+struct msg *new_msg_ism_change(uint32_t seqnr, struct in_addr ifaddr,
+                              struct in_addr area_id, uint8_t status)
 {
        struct msg_ism_change imsg;
 
@@ -629,9 +606,9 @@ struct msg *new_msg_ism_change(u_int32_t seqnr, struct in_addr ifaddr,
                       sizeof(struct msg_ism_change));
 }
 
-struct msg *new_msg_nsm_change(u_int32_t seqnr, struct in_addr ifaddr,
+struct msg *new_msg_nsm_change(uint32_t seqnr, struct in_addr ifaddr,
                               struct in_addr nbraddr, struct in_addr router_id,
-                              u_char status)
+                              uint8_t status)
 {
        struct msg_nsm_change nmsg;
 
@@ -645,15 +622,18 @@ struct msg *new_msg_nsm_change(u_int32_t seqnr, struct in_addr ifaddr,
                       sizeof(struct msg_nsm_change));
 }
 
-struct msg *new_msg_lsa_change_notify(u_char msgtype, u_int32_t seqnum,
+struct msg *new_msg_lsa_change_notify(uint8_t msgtype, uint32_t seqnum,
                                      struct in_addr ifaddr,
                                      struct in_addr area_id,
-                                     u_char is_self_originated,
+                                     uint8_t is_self_originated,
                                      struct lsa_header *data)
 {
-       u_char buf[OSPF_API_MAX_MSG_SIZE];
+       uint8_t buf[OSPF_API_MAX_MSG_SIZE];
        struct msg_lsa_change_notify *nmsg;
        unsigned int len;
+       size_t off_data = offsetof(struct msg_lsa_change_notify, data);
+       size_t data_maxs = sizeof(buf) - off_data;
+       struct lsa_header *nmsg_data = (struct lsa_header *)&buf[off_data];
 
        assert(data);
 
@@ -664,10 +644,9 @@ struct msg *new_msg_lsa_change_notify(u_char msgtype, u_int32_t seqnum,
        memset(&nmsg->pad, 0, sizeof(nmsg->pad));
 
        len = ntohs(data->length);
-       if (len > sizeof(buf) - offsetof(struct msg_lsa_change_notify, data))
-               len = sizeof(buf)
-                     - offsetof(struct msg_lsa_change_notify, data);
-       memcpy(&nmsg->data, data, len);
+       if (len > data_maxs)
+               len = data_maxs;
+       memcpy(nmsg_data, data, len);
        len += sizeof(struct msg_lsa_change_notify) - sizeof(struct lsa_header);
 
        return msg_new(msgtype, nmsg, seqnum, len);