Basic specfile taken from F10
[iproute2.git] / ip / ipxfrm.c
index fc0f0d9..24b2114 100644 (file)
@@ -2,17 +2,17 @@
 
 /*
  * Copyright (C)2004 USAGI/WIDE Project
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
@@ -32,7 +32,6 @@
 #include <sys/socket.h>
 #include <time.h>
 #include <netdb.h>
-#include <net/if.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
 #include <linux/xfrm.h>
 #include "utils.h"
 #include "xfrm.h"
 
+#define STRBUF_SIZE    (128)
+#define STRBUF_CAT(buf, str) \
+       do { \
+               int rest = sizeof(buf) - 1 - strlen(buf); \
+               if (rest > 0) { \
+                       int len = strlen(str); \
+                       if (len > rest) \
+                               len = rest; \
+                       strncat(buf, str, len); \
+                       buf[sizeof(buf) - 1] = '\0'; \
+               } \
+       } while(0);
+
 struct xfrm_filter filter;
 
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
 {
-       fprintf(stderr, 
+       fprintf(stderr,
                "Usage: ip xfrm XFRM_OBJECT { COMMAND | help }\n"
-               "where  XFRM_OBJECT := { state | policy }\n");
+               "where  XFRM_OBJECT := { state | policy | monitor }\n");
        exit(-1);
 }
 
@@ -81,6 +93,19 @@ int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits)
        return 0;
 }
 
+int xfrm_xfrmproto_is_ipsec(__u8 proto)
+{
+       return (proto ==  IPPROTO_ESP ||
+               proto ==  IPPROTO_AH  ||
+               proto ==  IPPROTO_COMP);
+}
+
+int xfrm_xfrmproto_is_ro(__u8 proto)
+{
+       return (proto ==  IPPROTO_ROUTING ||
+               proto ==  IPPROTO_DSTOPTS);
+}
+
 struct typeent {
        const char *t_name;
        int t_type;
@@ -88,6 +113,8 @@ struct typeent {
 
 static const struct typeent xfrmproto_types[]= {
        { "esp", IPPROTO_ESP }, { "ah", IPPROTO_AH }, { "comp", IPPROTO_COMP },
+       { "route2", IPPROTO_ROUTING }, { "hao", IPPROTO_DSTOPTS },
+       { "ipsec-any", IPSEC_PROTO_ANY },
        { NULL, -1 }
 };
 
@@ -109,6 +136,7 @@ int xfrm_xfrmproto_getbyname(char *name)
 
 const char *strxf_xfrmproto(__u8 proto)
 {
+       static char str[16];
        int i;
 
        for (i = 0; ; i++) {
@@ -120,12 +148,14 @@ const char *strxf_xfrmproto(__u8 proto)
                        return t->t_name;
        }
 
-       return NULL;
+       sprintf(str, "%u", proto);
+       return str;
 }
 
 static const struct typeent algo_types[]= {
        { "enc", XFRMA_ALG_CRYPT }, { "auth", XFRMA_ALG_AUTH },
-       { "comp", XFRMA_ALG_COMP }, { NULL, -1 }
+       { "comp", XFRMA_ALG_COMP }, { "aead", XFRMA_ALG_AEAD },
+       { NULL, -1 }
 };
 
 int xfrm_algotype_getbyname(char *name)
@@ -146,6 +176,7 @@ int xfrm_algotype_getbyname(char *name)
 
 const char *strxf_algotype(int type)
 {
+       static char str[32];
        int i;
 
        for (i = 0; ; i++) {
@@ -157,7 +188,8 @@ const char *strxf_algotype(int type)
                        return t->t_name;
        }
 
-       return NULL;
+       sprintf(str, "%d", type);
+       return str;
 }
 
 const char *strxf_mask8(__u8 mask)
@@ -225,14 +257,33 @@ const char *strxf_proto(__u8 proto)
        return p;
 }
 
+const char *strxf_ptype(__u8 ptype)
+{
+       static char str[16];
+
+       switch (ptype) {
+       case XFRM_POLICY_TYPE_MAIN:
+               strcpy(str, "main");
+               break;
+       case XFRM_POLICY_TYPE_SUB:
+               strcpy(str, "sub");
+               break;
+       default:
+               sprintf(str, "%u", ptype);
+               break;
+       }
+
+       return str;
+}
+
 void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
                        __u8 mode, __u32 reqid, __u16 family, int force_spi,
-                       FILE *fp, const char *prefix)
+                       FILE *fp, const char *prefix, const char *title)
 {
        char abuf[256];
 
-       if (prefix)
-               fprintf(fp, prefix);
+       if (title)
+               fputs(title, fp);
 
        memset(abuf, '\0', sizeof(abuf));
        fprintf(fp, "src %s ", rt_addr_n2a(family, sizeof(*saddr),
@@ -243,12 +294,11 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
        fprintf(fp, "%s", _SL_);
 
        if (prefix)
-               fprintf(fp, prefix);
+               fputs(prefix, fp);
        fprintf(fp, "\t");
 
        fprintf(fp, "proto %s ", strxf_xfrmproto(id->proto));
 
-
        if (show_stats > 0 || force_spi || id->spi) {
                __u32 spi = ntohl(id->spi);
                fprintf(fp, "spi 0x%08x", spi);
@@ -264,12 +314,21 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
 
        fprintf(fp, "mode ");
        switch (mode) {
-       case 0:
+       case XFRM_MODE_TRANSPORT:
                fprintf(fp, "transport");
                break;
-       case 1:
+       case XFRM_MODE_TUNNEL:
                fprintf(fp, "tunnel");
                break;
+       case XFRM_MODE_ROUTEOPTIMIZATION:
+               fprintf(fp, "ro");
+               break;
+       case XFRM_MODE_IN_TRIGGER:
+               fprintf(fp, "in_trigger");
+               break;
+       case XFRM_MODE_BEET:
+               fprintf(fp, "beet");
+               break;
        default:
                fprintf(fp, "%u", mode);
                break;
@@ -291,12 +350,12 @@ static const char *strxf_limit(__u64 limit)
 void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix)
 {
        if (prefix)
-               fprintf(fp, prefix);
+               fputs(prefix, fp);
        fprintf(fp, "stats:");
        fprintf(fp, "%s", _SL_);
 
        if (prefix)
-               fprintf(fp, prefix);
+               fputs(prefix, fp);
        fprintf(fp, "  ");
        fprintf(fp, "replay-window %u ", s->replay_window);
        fprintf(fp, "replay %u ", s->replay);
@@ -314,7 +373,7 @@ static const char *strxf_time(__u64 time)
                time_t t;
                struct tm *tp;
 
-               /* XXX: treat time in the same manner of kernel's 
+               /* XXX: treat time in the same manner of kernel's
                 * net/xfrm/xfrm_{user,state}.c
                 */
                t = (long)time;
@@ -332,12 +391,12 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
 {
        if (cfg) {
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "lifetime config:");
                fprintf(fp, "%s", _SL_);
 
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "  ");
                fprintf(fp, "limit: ");
                fprintf(fp, "soft ");
@@ -348,7 +407,7 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
                fprintf(fp, "%s", _SL_);
 
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "  ");
                fprintf(fp, "limit: ");
                fprintf(fp, "soft ");
@@ -359,7 +418,7 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
                fprintf(fp, "%s", _SL_);
 
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "  ");
                fprintf(fp, "expire add: ");
                fprintf(fp, "soft ");
@@ -370,7 +429,7 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
                fprintf(fp, "%s", _SL_);
 
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "  ");
                fprintf(fp, "expire use: ");
                fprintf(fp, "soft ");
@@ -382,19 +441,19 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
        }
        if (cur) {
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "lifetime current:");
                fprintf(fp, "%s", _SL_);
 
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "  ");
                fprintf(fp, "%llu(bytes), ", (unsigned long long) cur->bytes);
                fprintf(fp, "%llu(packets)", (unsigned long long) cur->packets);
                fprintf(fp, "%s", _SL_);
 
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "  ");
                fprintf(fp, "add %s ", strxf_time(cur->add_time));
                fprintf(fp, "use %s", strxf_time(cur->use_time));
@@ -415,7 +474,7 @@ void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
                f = preferred_family;
 
        if (prefix)
-               fprintf(fp, prefix);
+               fputs(prefix, fp);
 
        memset(abuf, '\0', sizeof(abuf));
        fprintf(fp, "src %s/%u ", rt_addr_n2a(f, sizeof(sel->saddr),
@@ -433,6 +492,7 @@ void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
        case IPPROTO_TCP:
        case IPPROTO_UDP:
        case IPPROTO_SCTP:
+       case IPPROTO_DCCP:
        default: /* XXX */
                if (sel->sport_mask)
                        fprintf(fp, "sport %u ", ntohs(sel->sport));
@@ -447,15 +507,18 @@ void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
                if (sel->dport_mask)
                        fprintf(fp, "code %u ", ntohs(sel->dport));
                break;
+       case IPPROTO_MH:
+               if (sel->sport_mask)
+                       fprintf(fp, "type %u ", ntohs(sel->sport));
+               if (sel->dport_mask) {
+                       if (show_stats > 0)
+                               fprintf(fp, "(dport) 0x%.4x ", sel->dport);
+               }
+               break;
        }
 
-       if (sel->ifindex > 0) {
-               char buf[IFNAMSIZ];
-
-               memset(buf, '\0', sizeof(buf));
-               if_indextoname(sel->ifindex, buf);
-               fprintf(fp, "dev %s ", buf);
-       }
+       if (sel->ifindex > 0)
+               fprintf(fp, "dev %s ", ll_index_to_name(sel->ifindex));
 
        if (show_stats > 0)
                fprintf(fp, "uid %u", sel->user);
@@ -463,14 +526,14 @@ void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
        fprintf(fp, "%s", _SL_);
 }
 
-static void xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
-                           FILE *fp, const char *prefix)
+static void __xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
+                             FILE *fp, const char *prefix, int newline)
 {
        int keylen;
        int i;
 
        if (prefix)
-               fprintf(fp, prefix);
+               fputs(prefix, fp);
 
        fprintf(fp, "%s ", strxf_algotype(type));
 
@@ -496,6 +559,32 @@ static void xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
                fprintf(fp, " (%d bits)", algo->alg_key_len);
 
  fin:
+       if (newline)
+               fprintf(fp, "%s", _SL_);
+}
+
+static inline void xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
+                                  FILE *fp, const char *prefix)
+{
+       return __xfrm_algo_print(algo, type, len, fp, prefix, 1);
+}
+
+static void xfrm_aead_print(struct xfrm_algo_aead *algo, int len,
+                           FILE *fp, const char *prefix)
+{
+       struct {
+               struct xfrm_algo algo;
+               char key[algo->alg_key_len / 8];
+       } base;
+
+       memcpy(base.algo.alg_name, algo->alg_name, sizeof(base.algo.alg_name));
+       base.algo.alg_key_len = algo->alg_key_len;
+       memcpy(base.algo.alg_key, algo->alg_key, algo->alg_key_len / 8);
+
+       __xfrm_algo_print(&base.algo, XFRMA_ALG_AEAD, len, fp, prefix, 0);
+
+       fprintf(fp, " %d", algo->alg_icv_len);
+
        fprintf(fp, "%s", _SL_);
 }
 
@@ -507,7 +596,7 @@ static void xfrm_tmpl_print(struct xfrm_user_tmpl *tmpls, int len,
 
        if (ntmpls <= 0) {
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "(ERROR \"tmpl\" truncated)");
                fprintf(fp, "%s", _SL_);
                return;
@@ -517,15 +606,14 @@ static void xfrm_tmpl_print(struct xfrm_user_tmpl *tmpls, int len,
                struct xfrm_user_tmpl *tmpl = &tmpls[i];
 
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
 
-               fprintf(fp, "tmpl");
                xfrm_id_info_print(&tmpl->saddr, &tmpl->id, tmpl->mode,
-                                  tmpl->reqid, family, 0, fp, prefix);
+                                  tmpl->reqid, family, 0, fp, prefix, "tmpl ");
 
                if (show_stats > 0 || tmpl->optional) {
                        if (prefix)
-                               fprintf(fp, prefix);
+                               fputs(prefix, fp);
                        fprintf(fp, "\t");
                        switch (tmpl->optional) {
                        case 0:
@@ -548,7 +636,7 @@ static void xfrm_tmpl_print(struct xfrm_user_tmpl *tmpls, int len,
 
                if (show_stats > 0) {
                        if (prefix)
-                               fprintf(fp, prefix);
+                               fputs(prefix, fp);
                        fprintf(fp, "\t");
                        fprintf(fp, "%s-mask %s ",
                                strxf_algotype(XFRMA_ALG_CRYPT),
@@ -574,6 +662,12 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
                                XFRMA_ALG_AUTH, RTA_PAYLOAD(rta), fp, prefix);
        }
 
+       if (tb[XFRMA_ALG_AEAD]) {
+               struct rtattr *rta = tb[XFRMA_ALG_AEAD];
+               xfrm_aead_print((struct xfrm_algo_aead *)RTA_DATA(rta),
+                               RTA_PAYLOAD(rta), fp, prefix);
+       }
+
        if (tb[XFRMA_ALG_CRYPT]) {
                struct rtattr *rta = tb[XFRMA_ALG_CRYPT];
                xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
@@ -591,7 +685,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
                char abuf[256];
 
                if (prefix)
-                       fprintf(fp, prefix);
+                       fputs(prefix, fp);
                fprintf(fp, "encap ");
 
                if (RTA_PAYLOAD(tb[XFRMA_ENCAP]) < sizeof(*e)) {
@@ -628,6 +722,192 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
                xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta),
                                RTA_PAYLOAD(rta), family, fp, prefix);
        }
+
+       if (tb[XFRMA_COADDR]) {
+               char abuf[256];
+               xfrm_address_t *coa;
+
+               if (prefix)
+                       fputs(prefix, fp);
+               fprintf(fp, "coa ");
+
+               coa = (xfrm_address_t *)RTA_DATA(tb[XFRMA_COADDR]);
+
+               if (RTA_PAYLOAD(tb[XFRMA_COADDR]) < sizeof(*coa)) {
+                       fprintf(fp, "(ERROR truncated)");
+                       fprintf(fp, "%s", _SL_);
+                       return;
+               }
+
+               memset(abuf, '\0', sizeof(abuf));
+               fprintf(fp, "%s",
+                       rt_addr_n2a(family, sizeof(*coa), coa,
+                                   abuf, sizeof(abuf)));
+               fprintf(fp, "%s", _SL_);
+       }
+
+       if (tb[XFRMA_LASTUSED]) {
+               __u64 lastused;
+
+               if (prefix)
+                       fputs(prefix, fp);
+               fprintf(fp, "lastused ");
+
+               if (RTA_PAYLOAD(tb[XFRMA_LASTUSED]) < sizeof(lastused)) {
+                       fprintf(fp, "(ERROR truncated)");
+                       fprintf(fp, "%s", _SL_);
+                       return;
+               }
+
+               lastused = *(__u64 *)RTA_DATA(tb[XFRMA_LASTUSED]);
+
+               fprintf(fp, "%s", strxf_time(lastused));
+               fprintf(fp, "%s", _SL_);
+       }
+}
+
+static int xfrm_selector_iszero(struct xfrm_selector *s)
+{
+       struct xfrm_selector s0;
+
+       memset(&s0, 0, sizeof(s0));
+
+       return (memcmp(&s0, s, sizeof(s0)) == 0);
+}
+
+void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
+                           struct rtattr *tb[], FILE *fp, const char *prefix,
+                           const char *title)
+{
+       char buf[STRBUF_SIZE];
+       int force_spi = xfrm_xfrmproto_is_ipsec(xsinfo->id.proto);
+
+       memset(buf, '\0', sizeof(buf));
+
+       xfrm_id_info_print(&xsinfo->saddr, &xsinfo->id, xsinfo->mode,
+                          xsinfo->reqid, xsinfo->family, force_spi, fp,
+                          prefix, title);
+
+       if (prefix)
+               STRBUF_CAT(buf, prefix);
+       STRBUF_CAT(buf, "\t");
+
+       fputs(buf, fp);
+       fprintf(fp, "replay-window %u ", xsinfo->replay_window);
+       if (show_stats > 0)
+               fprintf(fp, "seq 0x%08u ", xsinfo->seq);
+       if (show_stats > 0 || xsinfo->flags) {
+               __u8 flags = xsinfo->flags;
+
+               fprintf(fp, "flag ");
+               XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_NOECN, "noecn");
+               XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_DECAP_DSCP, "decap-dscp");
+               XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_NOPMTUDISC, "nopmtudisc");
+               XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_WILDRECV, "wildrecv");
+               if (flags)
+                       fprintf(fp, "%x", flags);
+       }
+       if (show_stats > 0)
+               fprintf(fp, " (0x%s)", strxf_mask8(xsinfo->flags));
+       fprintf(fp, "%s", _SL_);
+
+       xfrm_xfrma_print(tb, xsinfo->family, fp, buf);
+
+       if (!xfrm_selector_iszero(&xsinfo->sel)) {
+               char sbuf[STRBUF_SIZE];
+
+               memcpy(sbuf, buf, sizeof(sbuf));
+               STRBUF_CAT(sbuf, "sel ");
+
+               xfrm_selector_print(&xsinfo->sel, xsinfo->family, fp, sbuf);
+       }
+
+       if (show_stats > 0) {
+               xfrm_lifetime_print(&xsinfo->lft, &xsinfo->curlft, fp, buf);
+               xfrm_stats_print(&xsinfo->stats, fp, buf);
+       }
+}
+
+void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
+                           struct rtattr *tb[], FILE *fp, const char *prefix,
+                           const char *title)
+{
+       char buf[STRBUF_SIZE];
+
+       memset(buf, '\0', sizeof(buf));
+
+       xfrm_selector_print(&xpinfo->sel, preferred_family, fp, title);
+
+       if (prefix)
+               STRBUF_CAT(buf, prefix);
+       STRBUF_CAT(buf, "\t");
+
+       fputs(buf, fp);
+       fprintf(fp, "dir ");
+       switch (xpinfo->dir) {
+       case XFRM_POLICY_IN:
+               fprintf(fp, "in");
+               break;
+       case XFRM_POLICY_OUT:
+               fprintf(fp, "out");
+               break;
+       case XFRM_POLICY_FWD:
+               fprintf(fp, "fwd");
+               break;
+       default:
+               fprintf(fp, "%u", xpinfo->dir);
+               break;
+       }
+       fprintf(fp, " ");
+
+       switch (xpinfo->action) {
+       case XFRM_POLICY_ALLOW:
+               if (show_stats > 0)
+                       fprintf(fp, "action allow ");
+               break;
+       case XFRM_POLICY_BLOCK:
+               fprintf(fp, "action block ");
+               break;
+       default:
+               fprintf(fp, "action %u ", xpinfo->action);
+               break;
+       }
+
+       if (show_stats)
+               fprintf(fp, "index %u ", xpinfo->index);
+       fprintf(fp, "priority %u ", xpinfo->priority);
+
+       if (tb[XFRMA_POLICY_TYPE]) {
+               struct xfrm_userpolicy_type *upt;
+
+               fprintf(fp, "ptype ");
+
+               if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt))
+                       fprintf(fp, "(ERROR truncated)");
+
+               upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
+               fprintf(fp, "%s ", strxf_ptype(upt->type));
+       }
+
+       if (show_stats > 0)
+               fprintf(fp, "share %s ", strxf_share(xpinfo->share));
+
+       if (show_stats > 0 || xpinfo->flags) {
+               __u8 flags = xpinfo->flags;
+
+               fprintf(fp, "flag ");
+               XFRM_FLAG_PRINT(fp, flags, XFRM_POLICY_LOCALOK, "localok");
+               if (flags)
+                       fprintf(fp, "%x", flags);
+       }
+       if (show_stats > 0)
+               fprintf(fp, " (0x%s)", strxf_mask8(xpinfo->flags));
+       fprintf(fp, "%s", _SL_);
+
+       if (show_stats > 0)
+               xfrm_lifetime_print(&xpinfo->lft, &xpinfo->curlft, fp, buf);
+
+       xfrm_xfrma_print(tb, xpinfo->sel.family, fp, buf);
 }
 
 int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
@@ -723,9 +1003,15 @@ int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp)
        char **argv = *argvp;
 
        if (matches(*argv, "transport") == 0)
-               *mode = 0;
+               *mode = XFRM_MODE_TRANSPORT;
        else if (matches(*argv, "tunnel") == 0)
-               *mode = 1;
+               *mode = XFRM_MODE_TUNNEL;
+       else if (matches(*argv, "ro") == 0)
+               *mode = XFRM_MODE_ROUTEOPTIMIZATION;
+       else if (matches(*argv, "in_trigger") == 0)
+               *mode = XFRM_MODE_IN_TRIGGER;
+       else if (matches(*argv, "beet") == 0)
+               *mode = XFRM_MODE_BEET;
        else
                invarg("\"MODE\" is invalid", *argv);
 
@@ -869,6 +1155,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
                case IPPROTO_TCP:
                case IPPROTO_UDP:
                case IPPROTO_SCTP:
+               case IPPROTO_DCCP:
                        break;
                default:
                        fprintf(stderr, "\"sport\" and \"dport\" are invalid with proto=%s\n", strxf_proto(sel->proto));
@@ -879,6 +1166,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
                switch (sel->proto) {
                case IPPROTO_ICMP:
                case IPPROTO_ICMPV6:
+               case IPPROTO_MH:
                        break;
                default:
                        fprintf(stderr, "\"type\" and \"code\" are invalid with proto=%s\n", strxf_proto(sel->proto));
@@ -938,7 +1226,7 @@ int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp)
                        if (strcmp(*argv, "none") == 0)
                                ifindex = 0;
                        else {
-                               ifindex = if_nametoindex(*argv);
+                               ifindex = ll_name_to_index(*argv);
                                if (ifindex <= 0)
                                        invarg("\"DEV\" is invalid", *argv);
                        }
@@ -1038,10 +1326,12 @@ int do_xfrm(int argc, char **argv)
                usage();
 
        if (matches(*argv, "state") == 0 ||
-           matches(*argv, "sa") == 0) {
+           matches(*argv, "sa") == 0)
                return do_xfrm_state(argc-1, argv+1);
-       else if (matches(*argv, "policy") == 0)
+       else if (matches(*argv, "policy") == 0)
                return do_xfrm_policy(argc-1, argv+1);
+       else if (matches(*argv, "monitor") == 0)
+               return do_xfrm_monitor(argc-1, argv+1);
        else if (matches(*argv, "help") == 0) {
                usage();
                fprintf(stderr, "xfrm Object \"%s\" is unknown.\n", *argv);