static void usage(void) { fprintf(stderr, "Usage: ip xfrm state { add | update } ID [ ALGO-LIST ] [ mode MODE ]\n"); fprintf(stderr, " [ mark MARK [ mask MASK ] ] [ reqid REQID ] [ seq SEQ ]\n"); fprintf(stderr, " [ replay-window SIZE ] [ replay-seq SEQ ] [ replay-oseq SEQ ]\n"); fprintf(stderr, " [ replay-seq-hi SEQ ] [ replay-oseq-hi SEQ ]\n"); fprintf(stderr, " [ flag FLAG-LIST ] [ sel SELECTOR ] [ LIMIT-LIST ] [ encap ENCAP ]\n"); fprintf(stderr, " [ coa ADDR[/PLEN] ] [ ctx CTX ] [ extra-flag EXTRA-FLAG-LIST ]\n"); fprintf(stderr, "Usage: ip xfrm state allocspi ID [ mode MODE ] [ mark MARK [ mask MASK ] ]\n"); fprintf(stderr, " [ reqid REQID ] [ seq SEQ ] [ min SPI max SPI ]\n"); fprintf(stderr, "Usage: ip xfrm state { delete | get } ID [ mark MARK [ mask MASK ] ]\n"); fprintf(stderr, "Usage: ip xfrm state { deleteall | list } [ ID ] [ mode MODE ] [ reqid REQID ]\n"); fprintf(stderr, " [ flag FLAG-LIST ]\n"); fprintf(stderr, "Usage: ip xfrm state flush [ proto XFRM-PROTO ]\n"); fprintf(stderr, "Usage: ip xfrm state count\n"); fprintf(stderr, "ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ]\n"); fprintf(stderr, "XFRM-PROTO := "); fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_ESP)); fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_AH)); fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_COMP)); fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_ROUTING)); fprintf(stderr, "%s\n", strxf_xfrmproto(IPPROTO_DSTOPTS)); fprintf(stderr, "ALGO-LIST := [ ALGO-LIST ] ALGO\n"); fprintf(stderr, "ALGO := { "); fprintf(stderr, "%s | ", strxf_algotype(XFRMA_ALG_CRYPT)); fprintf(stderr, "%s", strxf_algotype(XFRMA_ALG_AUTH)); fprintf(stderr, " } ALGO-NAME ALGO-KEYMAT |\n"); fprintf(stderr, " %s", strxf_algotype(XFRMA_ALG_AUTH_TRUNC)); fprintf(stderr, " ALGO-NAME ALGO-KEYMAT ALGO-TRUNC-LEN |\n"); fprintf(stderr, " %s", strxf_algotype(XFRMA_ALG_AEAD)); fprintf(stderr, " ALGO-NAME ALGO-KEYMAT ALGO-ICV-LEN |\n"); fprintf(stderr, " %s", strxf_algotype(XFRMA_ALG_COMP)); fprintf(stderr, " ALGO-NAME\n"); fprintf(stderr, "MODE := transport | tunnel | beet | ro | in_trigger\n"); fprintf(stderr, "FLAG-LIST := [ FLAG-LIST ] FLAG\n"); fprintf(stderr, "FLAG := noecn | decap-dscp | nopmtudisc | wildrecv | icmp | af-unspec | align4 | esn\n"); fprintf(stderr, "EXTRA-FLAG-LIST := [ EXTRA-FLAG-LIST ] EXTRA-FLAG\n"); fprintf(stderr, "EXTRA-FLAG := dont-encap-dscp\n"); fprintf(stderr, "SELECTOR := [ src ADDR[/PLEN] ] [ dst ADDR[/PLEN] ] [ dev DEV ] [ UPSPEC ]\n"); fprintf(stderr, "UPSPEC := proto { { "); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_TCP)); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_UDP)); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_SCTP)); fprintf(stderr, "%s", strxf_proto(IPPROTO_DCCP)); fprintf(stderr, " } [ sport PORT ] [ dport PORT ] |\n"); fprintf(stderr, " { "); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_ICMP)); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_ICMPV6)); fprintf(stderr, "%s", strxf_proto(IPPROTO_MH)); fprintf(stderr, " } [ type NUMBER ] [ code NUMBER ] |\n"); fprintf(stderr, " %s", strxf_proto(IPPROTO_GRE)); fprintf(stderr, " [ key { DOTTED-QUAD | NUMBER } ] | PROTO }\n"); fprintf(stderr, "LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT\n"); fprintf(stderr, "LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n"); fprintf(stderr, " { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n"); fprintf(stderr, "ENCAP := { espinudp | espinudp-nonike } SPORT DPORT OADDR\n"); exit(-1); }
void xfrm_selector_print(struct xfrm_selector *sel, __u16 family, FILE *fp, const char *prefix) { char abuf[256]; __u16 f; f = sel->family; if (f == AF_UNSPEC) f = family; if (f == AF_UNSPEC) f = preferred_family; if (prefix) fprintf(fp, prefix); memset(abuf, '\0', sizeof(abuf)); fprintf(fp, "src %s/%u ", rt_addr_n2a(f, sizeof(sel->saddr), &sel->saddr, abuf, sizeof(abuf)), sel->prefixlen_s); memset(abuf, '\0', sizeof(abuf)); fprintf(fp, "dst %s/%u ", rt_addr_n2a(f, sizeof(sel->daddr), &sel->daddr, abuf, sizeof(abuf)), sel->prefixlen_d); if (sel->proto) fprintf(fp, "proto %s ", strxf_proto(sel->proto)); switch (sel->proto) { case IPPROTO_TCP: case IPPROTO_UDP: case IPPROTO_SCTP: default: /* XXX */ if (sel->sport_mask) fprintf(fp, "sport %u ", ntohs(sel->sport)); if (sel->dport_mask) fprintf(fp, "dport %u ", ntohs(sel->dport)); break; case IPPROTO_ICMP: case IPPROTO_ICMPV6: /* type/code is stored at sport/dport in selector */ if (sel->sport_mask) fprintf(fp, "type %u ", ntohs(sel->sport)); if (sel->dport_mask) fprintf(fp, "code %u ", ntohs(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 (show_stats > 0) fprintf(fp, "uid %u", sel->user); fprintf(fp, "%s", _SL_); }
static int xfrm_ae_print(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct xfrm_aevent_id *id = NLMSG_DATA(n); char abuf[256]; fprintf(fp, "Async event "); xfrm_ae_flags_print(id->flags, arg); fprintf(fp,"\n\t"); memset(abuf, '\0', sizeof(abuf)); fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family, sizeof(id->saddr), &id->saddr, abuf, sizeof(abuf))); memset(abuf, '\0', sizeof(abuf)); fprintf(fp, "dst %s ", rt_addr_n2a(id->sa_id.family, sizeof(id->sa_id.daddr), &id->sa_id.daddr, abuf, sizeof(abuf))); fprintf(fp, " reqid 0x%x", id->reqid); fprintf(fp, " protocol %s ", strxf_proto(id->sa_id.proto)); fprintf(fp, " SPI 0x%x", ntohl(id->sa_id.spi)); fprintf(fp, "\n"); fflush(fp); return 0; }
static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, FILE *fp) { fprintf(fp, "dst %s ", rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr)); fprintf(fp, " reqid 0x%x", reqid); fprintf(fp, " protocol %s ", strxf_proto(sa_id->proto)); fprintf(fp, " SPI 0x%x", ntohl(sa_id->spi)); }
static void usage(void) { fprintf(stderr, "Usage: ip xfrm policy { add | update } SELECTOR dir DIR [ ctx CTX ]\n"); fprintf(stderr, " [ mark MARK [ mask MASK ] ] [ index INDEX ] [ ptype PTYPE ]\n"); fprintf(stderr, " [ action ACTION ] [ priority PRIORITY ] [ flag FLAG-LIST ]\n"); fprintf(stderr, " [ LIMIT-LIST ] [ TMPL-LIST ]\n"); fprintf(stderr, "Usage: ip xfrm policy { delete | get } { SELECTOR | index INDEX } dir DIR\n"); fprintf(stderr, " [ ctx CTX ] [ mark MARK [ mask MASK ] ] [ ptype PTYPE ]\n"); fprintf(stderr, "Usage: ip xfrm policy { deleteall | list } [ SELECTOR ] [ dir DIR ]\n"); fprintf(stderr, " [ index INDEX ] [ ptype PTYPE ] [ action ACTION ] [ priority PRIORITY ]\n"); fprintf(stderr, " [ flag FLAG-LIST ]\n"); fprintf(stderr, "Usage: ip xfrm policy flush [ ptype PTYPE ]\n"); fprintf(stderr, "Usage: ip xfrm policy count\n"); fprintf(stderr, "Usage: ip xfrm policy set [ hthresh4 LBITS RBITS ] [ hthresh6 LBITS RBITS ]\n"); fprintf(stderr, "SELECTOR := [ src ADDR[/PLEN] ] [ dst ADDR[/PLEN] ] [ dev DEV ] [ UPSPEC ]\n"); fprintf(stderr, "UPSPEC := proto { { "); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_TCP)); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_UDP)); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_SCTP)); fprintf(stderr, "%s", strxf_proto(IPPROTO_DCCP)); fprintf(stderr, " } [ sport PORT ] [ dport PORT ] |\n"); fprintf(stderr, " { "); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_ICMP)); fprintf(stderr, "%s | ", strxf_proto(IPPROTO_ICMPV6)); fprintf(stderr, "%s", strxf_proto(IPPROTO_MH)); fprintf(stderr, " } [ type NUMBER ] [ code NUMBER ] |\n"); fprintf(stderr, " %s", strxf_proto(IPPROTO_GRE)); fprintf(stderr, " [ key { DOTTED-QUAD | NUMBER } ] | PROTO }\n"); fprintf(stderr, "DIR := in | out | fwd\n"); fprintf(stderr, "PTYPE := main | sub\n"); fprintf(stderr, "ACTION := allow | block\n"); fprintf(stderr, "FLAG-LIST := [ FLAG-LIST ] FLAG\n"); fprintf(stderr, "FLAG := localok | icmp\n"); fprintf(stderr, "LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT\n"); fprintf(stderr, "LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n"); fprintf(stderr, " { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n"); fprintf(stderr, "TMPL-LIST := [ TMPL-LIST ] tmpl TMPL\n"); fprintf(stderr, "TMPL := ID [ mode MODE ] [ reqid REQID ] [ level LEVEL ]\n"); fprintf(stderr, "ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ]\n"); fprintf(stderr, "XFRM-PROTO := "); fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_ESP)); fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_AH)); fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_COMP)); fprintf(stderr, "%s | ", strxf_xfrmproto(IPPROTO_ROUTING)); fprintf(stderr, "%s\n", strxf_xfrmproto(IPPROTO_DSTOPTS)); fprintf(stderr, "MODE := transport | tunnel | beet | ro | in_trigger\n"); fprintf(stderr, "LEVEL := required | use\n"); exit(-1); }
static int xfrm_selector_upspec_parse(struct xfrm_selector *sel, int *argcp, char ***argvp) { int argc = *argcp; char **argv = *argvp; char *sportp = NULL; char *dportp = NULL; char *typep = NULL; char *codep = NULL; while (1) { if (strcmp(*argv, "proto") == 0) { __u8 upspec; NEXT_ARG(); if (strcmp(*argv, "any") == 0) upspec = 0; else { struct protoent *pp; pp = getprotobyname(*argv); if (pp) upspec = pp->p_proto; else { if (get_u8(&upspec, *argv, 0)) invarg("\"PROTO\" is invalid", *argv); } } sel->proto = upspec; filter.upspec_proto_mask = XFRM_FILTER_MASK_FULL; } else if (strcmp(*argv, "sport") == 0) { sportp = *argv; NEXT_ARG(); if (get_u16(&sel->sport, *argv, 0)) invarg("\"PORT\" is invalid", *argv); sel->sport = htons(sel->sport); if (sel->sport) sel->sport_mask = ~((__u16)0); filter.upspec_sport_mask = XFRM_FILTER_MASK_FULL; } else if (strcmp(*argv, "dport") == 0) { dportp = *argv; NEXT_ARG(); if (get_u16(&sel->dport, *argv, 0)) invarg("\"PORT\" is invalid", *argv); sel->dport = htons(sel->dport); if (sel->dport) sel->dport_mask = ~((__u16)0); filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL; } else if (strcmp(*argv, "type") == 0) { typep = *argv; NEXT_ARG(); if (get_u16(&sel->sport, *argv, 0) || (sel->sport & ~((__u16)0xff))) invarg("\"type\" value is invalid", *argv); sel->sport = htons(sel->sport); sel->sport_mask = ~((__u16)0); filter.upspec_sport_mask = XFRM_FILTER_MASK_FULL; } else if (strcmp(*argv, "code") == 0) { codep = *argv; NEXT_ARG(); if (get_u16(&sel->dport, *argv, 0) || (sel->dport & ~((__u16)0xff))) invarg("\"code\" value is invalid", *argv); sel->dport = htons(sel->dport); sel->dport_mask = ~((__u16)0); filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL; } else { PREV_ARG(); /* back track */ break; } if (!NEXT_ARG_OK()) break; NEXT_ARG(); } if (argc == *argcp) missarg("UPSPEC"); if (sportp || dportp) { switch (sel->proto) { 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)); exit(1); } } if (typep || codep) { 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)); exit(1); } } *argcp = argc; *argvp = argv; return 0; }
void xfrm_selector_print(struct xfrm_selector *sel, __u16 family, FILE *fp, const char *prefix) { char abuf[256]; __u16 f; f = sel->family; if (f == AF_UNSPEC) f = family; if (f == AF_UNSPEC) f = preferred_family; if (prefix) fputs(prefix, fp); memset(abuf, '\0', sizeof(abuf)); fprintf(fp, "src %s/%u ", rt_addr_n2a(f, sizeof(sel->saddr), &sel->saddr, abuf, sizeof(abuf)), sel->prefixlen_s); memset(abuf, '\0', sizeof(abuf)); fprintf(fp, "dst %s/%u ", rt_addr_n2a(f, sizeof(sel->daddr), &sel->daddr, abuf, sizeof(abuf)), sel->prefixlen_d); if (sel->proto) fprintf(fp, "proto %s ", strxf_proto(sel->proto)); switch (sel->proto) { 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)); if (sel->dport_mask) fprintf(fp, "dport %u ", ntohs(sel->dport)); break; case IPPROTO_ICMP: case IPPROTO_ICMPV6: /* type/code is stored at sport/dport in selector */ if (sel->sport_mask) fprintf(fp, "type %u ", ntohs(sel->sport)); if (sel->dport_mask) fprintf(fp, "code %u ", ntohs(sel->dport)); break; case IPPROTO_GRE: if (sel->sport_mask || sel->dport_mask) fprintf(fp, "key %u ", (((__u32)ntohs(sel->sport)) << 16) + 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) fprintf(fp, "dev %s ", ll_index_to_name(sel->ifindex)); if (show_stats > 0) fprintf(fp, "uid %u", sel->user); fprintf(fp, "%s", _SL_); }