]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Minor fixes from Masahide for XFRM dynamic keying
authorshemminger <shemminger>
Mon, 7 Nov 2005 18:39:30 +0000 (18:39 +0000)
committershemminger <shemminger>
Mon, 7 Nov 2005 18:39:30 +0000 (18:39 +0000)
ChangeLog
ip/xfrm.h
ip/xfrm_monitor.c
ip/xfrm_policy.c
ip/xfrm_state.c

index 60e4ba10ec80695f1b0828e21d36fe388cff9cdc..cd70102d5e5322f9c52be007fedfdff39fcd5c17 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-11-07  Masahide NAKAMURA <nakam@linux-ipv6.org>
+
+       * Updating for 2.6.14
+       - Show UPD{SA,POLICY} message information from kernel instead of error
+       - Add lengh check of deleting message from kernel
+       - Use macro for struct xfrm_user{sa,policy}_id
+
+       * Minor fix:
+       - Add fflush at the end of normal dump
+
 2005-11-01  Jamal Hadi Salim <hadi@znyx.com>
 
        * Fix handling of XFRM monitor and state
index 60d597e9f31a7f1d795f5cedb77547a5282fe295..2f33c063cfa05e768f919dff581df88a007846ee 100644 (file)
--- a/ip/xfrm.h
+++ b/ip/xfrm.h
 #define XFRMP_RTA(x)  ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_info))))
 #define XFRMP_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_info))
 
+#define XFRMSID_RTA(x)  ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_id))))
+#define XFRMSID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_id))
+
+#define XFRMPID_RTA(x)  ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_id))))
+#define XFRMPID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_id))
+
 #define XFRMACQ_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_acquire))))
 #define XFRMEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_expire))))
 #define XFRMPEXP_RTA(x)        ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire))))
index f5904289018bf9c117519e87d71b835f187caa42..153621f741593a02437e942c45ffa9285436ac2f 100644 (file)
@@ -103,6 +103,7 @@ static int xfrm_acquire_print(const struct sockaddr_nl *who,
 
        if (oneline)
                fprintf(fp, "\n");
+       fflush(fp);
 
        return 0;
 }
@@ -116,14 +117,16 @@ static int xfrm_accept_msg(const struct sockaddr_nl *who,
                print_timestamp(fp);
 
        if (n->nlmsg_type == XFRM_MSG_NEWSA ||
-            n->nlmsg_type == XFRM_MSG_DELSA ||
-            n->nlmsg_type == XFRM_MSG_UPDSA) {
+           n->nlmsg_type == XFRM_MSG_DELSA ||
+           n->nlmsg_type == XFRM_MSG_UPDSA ||
+           n->nlmsg_type == XFRM_MSG_EXPIRE) {
                xfrm_state_print(who, n, arg);
                return 0;
        }
        if (n->nlmsg_type == XFRM_MSG_NEWPOLICY ||
-            n->nlmsg_type == XFRM_MSG_DELPOLICY ||
-            n->nlmsg_type == XFRM_MSG_UPDPOLICY) {
+           n->nlmsg_type == XFRM_MSG_DELPOLICY ||
+           n->nlmsg_type == XFRM_MSG_UPDPOLICY ||
+           n->nlmsg_type == XFRM_MSG_POLEXPIRE) {
                xfrm_policy_print(who, n, arg);
                return 0;
        }
@@ -132,14 +135,6 @@ static int xfrm_accept_msg(const struct sockaddr_nl *who,
                xfrm_acquire_print(who, n, arg);
                return 0;
        }
-       if (n->nlmsg_type == XFRM_MSG_EXPIRE) {
-               xfrm_state_print(who, n, arg);
-               return 0;
-       }
-       if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) {
-               xfrm_policy_print(who, n, arg);
-               return 0;
-       }
        if (n->nlmsg_type == XFRM_MSG_FLUSHSA) {
                /* XXX: Todo: show proto in xfrm_usersa_flush */
                fprintf(fp, "Flushed state\n");
index e295eb96f3e62a7c58e47f018910b351da914bb2..433b5136b4782dfb56a4d8e1bbd0c97b891431bc 100644 (file)
@@ -345,24 +345,23 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
 
        if (n->nlmsg_type != XFRM_MSG_NEWPOLICY &&
            n->nlmsg_type != XFRM_MSG_DELPOLICY &&
+           n->nlmsg_type != XFRM_MSG_UPDPOLICY &&
            n->nlmsg_type != XFRM_MSG_POLEXPIRE) {
                fprintf(stderr, "Not a policy: %08x %08x %08x\n",
                        n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
                return 0;
        }
 
-       if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) {
+       if (n->nlmsg_type == XFRM_MSG_DELPOLICY)  {
+               xpid = NLMSG_DATA(n);
+               len -= NLMSG_LENGTH(sizeof(*xpid));
+       } else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) {
                xpexp = NLMSG_DATA(n);
                xpinfo = &xpexp->pol;
-
                len -= NLMSG_LENGTH(sizeof(*xpexp));
-       } else if (n->nlmsg_type == XFRM_MSG_DELPOLICY)  {
-               xpid = NLMSG_DATA(n);
-               len -= NLMSG_LENGTH(sizeof(*xpid));
        } else {
                xpexp = NULL;
                xpinfo = NLMSG_DATA(n);
-
                len -= NLMSG_LENGTH(sizeof(*xpinfo));
        }
 
@@ -371,31 +370,37 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
                return -1;
        }
 
-       if (!xfrm_policy_filter_match(xpinfo))
+       if (xpinfo && !xfrm_policy_filter_match(xpinfo))
                return 0;
 
-       if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
+       if (n->nlmsg_type == XFRM_MSG_DELPOLICY)
+               fprintf(fp, "Deleted ");
+       else if (n->nlmsg_type == XFRM_MSG_UPDPOLICY)
+               fprintf(fp, "Updated ");
+       else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
+               fprintf(fp, "Expired ");
+
+       if (n->nlmsg_type == XFRM_MSG_DELPOLICY)
+               rta = XFRMPID_RTA(xpid);
+       else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
                rta = XFRMPEXP_RTA(xpexp);
-       else if (n->nlmsg_type == XFRM_MSG_DELPOLICY) 
-               rta = (struct rtattr*)(((char*)(xpid)) + NLMSG_ALIGN(sizeof(*xpid)));
        else
                rta = XFRMP_RTA(xpinfo);
 
        parse_rtattr(tb, XFRMA_MAX, rta, len);
 
        if (n->nlmsg_type == XFRM_MSG_DELPOLICY) {
-               fprintf(fp, "Deleted ");
                //xfrm_policy_id_print();
-               
-               if (tb[XFRMA_POLICY])
-               xpinfo = (struct xfrm_userpolicy_info *)RTA_DATA(tb[XFRMA_POLICY]);
-               else {
-                       fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY ");
-                       return 0;
+               if (!tb[XFRMA_POLICY]) {
+                       fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: no XFRMA_POLICY\n");
+                       return -1;
                }
-
-       } else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
-               fprintf(fp, "Expired ");
+               if (RTA_PAYLOAD(tb[XFRMA_POLICY]) < sizeof(*xpinfo)) {
+                       fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n");
+                       return -1;
+               }
+               xpinfo = (struct xfrm_userpolicy_info *)RTA_DATA(tb[XFRMA_POLICY]);
+       }
 
        xfrm_policy_info_print(xpinfo, tb, fp, NULL, NULL);
 
@@ -407,6 +412,7 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
 
        if (oneline)
                fprintf(fp, "\n");
+       fflush(fp);
 
        return 0;
 }
index db7de0c1350a22a2c79281ea4e91af69845523df..3eefaff82c7dce49f7d4c4f06f43490aa6b3e7c0 100644 (file)
@@ -565,25 +565,24 @@ int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
 
        if (n->nlmsg_type != XFRM_MSG_NEWSA &&
            n->nlmsg_type != XFRM_MSG_DELSA &&
+           n->nlmsg_type != XFRM_MSG_UPDSA &&
            n->nlmsg_type != XFRM_MSG_EXPIRE) {
                fprintf(stderr, "Not a state: %08x %08x %08x\n",
                        n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
                return 0;
        }
 
-       if (n->nlmsg_type == XFRM_MSG_EXPIRE) {
+       if (n->nlmsg_type == XFRM_MSG_DELSA) {
+               /* Dont blame me for this .. Herbert made me do it */
+               xsid = NLMSG_DATA(n);
+               len -= NLMSG_LENGTH(sizeof(*xsid));
+       } else if (n->nlmsg_type == XFRM_MSG_EXPIRE) {
                xexp = NLMSG_DATA(n);
                xsinfo = &xexp->state;
-
                len -= NLMSG_LENGTH(sizeof(*xexp));
-       } else if (n->nlmsg_type == XFRM_MSG_DELSA) {
-               /* Dont blame me for this .. Herbert made me do it */
-               xsid = NLMSG_DATA(n);
-               len -= NLMSG_LENGTH(sizeof(struct xfrm_usersa_id));
        } else {
                xexp = NULL;
                xsinfo = NLMSG_DATA(n);
-
                len -= NLMSG_LENGTH(sizeof(*xsinfo));
        }
 
@@ -592,33 +591,37 @@ int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
                return -1;
        }
 
-       if (!xfrm_state_filter_match(xsinfo))
+       if (xsinfo && !xfrm_state_filter_match(xsinfo))
                return 0;
 
-       if (n->nlmsg_type == XFRM_MSG_DELSA) {
+       if (n->nlmsg_type == XFRM_MSG_DELSA)
                fprintf(fp, "Deleted ");
-               //xfrm_state_print_id();
-       }
+       else if (n->nlmsg_type == XFRM_MSG_UPDSA)
+               fprintf(fp, "Updated ");
        else if (n->nlmsg_type == XFRM_MSG_EXPIRE)
                fprintf(fp, "Expired ");
 
-       if (n->nlmsg_type == XFRM_MSG_EXPIRE)
+       if (n->nlmsg_type == XFRM_MSG_DELSA)
+               rta = XFRMSID_RTA(xsid);
+       else if (n->nlmsg_type == XFRM_MSG_EXPIRE)
                rta = XFRMEXP_RTA(xexp);
-       else if (n->nlmsg_type == XFRM_MSG_DELSA)
-               rta = (struct rtattr*)(((char*)(xsid)) + NLMSG_ALIGN(sizeof(*xsid)));
        else 
                rta = XFRMS_RTA(xsinfo);
 
-
        parse_rtattr(tb, XFRMA_MAX, rta, len);
 
        if (n->nlmsg_type == XFRM_MSG_DELSA) {
-               if (tb[XFRMA_SA])
-                       xsinfo = (struct xfrm_usersa_info *)RTA_DATA(tb[XFRMA_SA]);
-               else {
-                       fprintf(stderr, "Buggy XFRM_MSG_DELSA ");
-                       return 0;
+               //xfrm_policy_id_print();
+
+               if (!tb[XFRMA_SA]) {
+                       fprintf(stderr, "Buggy XFRM_MSG_DELSA: no XFRMA_SA\n");
+                       return -1;
+               }
+               if (RTA_PAYLOAD(tb[XFRMA_SA]) < sizeof(*xsinfo)) {
+                       fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n");
+                       return -1;
                }
+               xsinfo = (struct xfrm_usersa_info *)RTA_DATA(tb[XFRMA_SA]);
        }
 
        xfrm_state_info_print(xsinfo, tb, fp, NULL, NULL);
@@ -631,6 +634,7 @@ int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
 
        if (oneline)
                fprintf(fp, "\n");
+       fflush(fp);
 
        return 0;
 }