~ubuntu-branches/ubuntu/precise/iproute/precise

« back to all changes in this revision

Viewing changes to ip/ipxfrm.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-06-11 13:31:12 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070611133112-0rtfv32yfs8loo0r
Tags: 20070313-1ubuntu1
* Merge from debian unstable, remaining changes:
  - linux-kernel-headers -> linux-libc-dev B-D rename.
  - MAX_ROUNDS patch to ip/ipaddress.c
  - Ubuntu maintainer foobar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
/*
4
4
 * Copyright (C)2004 USAGI/WIDE Project
5
 
 * 
 
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
8
8
 * the Free Software Foundation; either version 2 of the License, or
9
9
 * (at your option) any later version.
10
 
 * 
 
10
 *
11
11
 * This program is distributed in the hope that it will be useful,
12
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
14
 * GNU General Public License for more details.
15
 
 * 
 
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
17
 * along with this program; if not, write to the Free Software
18
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
59
59
 
60
60
static void usage(void)
61
61
{
62
 
        fprintf(stderr, 
 
62
        fprintf(stderr,
63
63
                "Usage: ip xfrm XFRM_OBJECT { COMMAND | help }\n"
64
64
                "where  XFRM_OBJECT := { state | policy | monitor }\n");
65
65
        exit(-1);
94
94
        return 0;
95
95
}
96
96
 
 
97
int xfrm_xfrmproto_is_ipsec(__u8 proto)
 
98
{
 
99
        return (proto ==  IPPROTO_ESP ||
 
100
                proto ==  IPPROTO_AH  ||
 
101
                proto ==  IPPROTO_COMP);
 
102
}
 
103
 
 
104
int xfrm_xfrmproto_is_ro(__u8 proto)
 
105
{
 
106
        return (proto ==  IPPROTO_ROUTING ||
 
107
                proto ==  IPPROTO_DSTOPTS);
 
108
}
 
109
 
97
110
struct typeent {
98
111
        const char *t_name;
99
112
        int t_type;
101
114
 
102
115
static const struct typeent xfrmproto_types[]= {
103
116
        { "esp", IPPROTO_ESP }, { "ah", IPPROTO_AH }, { "comp", IPPROTO_COMP },
 
117
        { "route2", IPPROTO_ROUTING }, { "hao", IPPROTO_DSTOPTS },
104
118
        { NULL, -1 }
105
119
};
106
120
 
276
290
 
277
291
        fprintf(fp, "mode ");
278
292
        switch (mode) {
279
 
        case 0:
 
293
        case XFRM_MODE_TRANSPORT:
280
294
                fprintf(fp, "transport");
281
295
                break;
282
 
        case 1:
 
296
        case XFRM_MODE_TUNNEL:
283
297
                fprintf(fp, "tunnel");
284
298
                break;
 
299
        case XFRM_MODE_ROUTEOPTIMIZATION:
 
300
                fprintf(fp, "ro");
 
301
                break;
 
302
        case XFRM_MODE_IN_TRIGGER:
 
303
                fprintf(fp, "in_trigger");
 
304
                break;
 
305
        case XFRM_MODE_BEET:
 
306
                fprintf(fp, "beet");
 
307
                break;
285
308
        default:
286
309
                fprintf(fp, "%u", mode);
287
310
                break;
326
349
                time_t t;
327
350
                struct tm *tp;
328
351
 
329
 
                /* XXX: treat time in the same manner of kernel's 
 
352
                /* XXX: treat time in the same manner of kernel's
330
353
                 * net/xfrm/xfrm_{user,state}.c
331
354
                 */
332
355
                t = (long)time;
460
483
                if (sel->dport_mask)
461
484
                        fprintf(fp, "code %u ", ntohs(sel->dport));
462
485
                break;
 
486
        case IPPROTO_MH:
 
487
                if (sel->sport_mask)
 
488
                        fprintf(fp, "type %u ", ntohs(sel->sport));
 
489
                if (sel->dport_mask) {
 
490
                        if (show_stats > 0)
 
491
                                fprintf(fp, "(dport) 0x%.4x ", sel->dport);
 
492
                }
 
493
                break;
463
494
        }
464
495
 
465
496
        if (sel->ifindex > 0) {
640
671
                xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta),
641
672
                                RTA_PAYLOAD(rta), family, fp, prefix);
642
673
        }
 
674
 
 
675
        if (tb[XFRMA_COADDR]) {
 
676
                char abuf[256];
 
677
                xfrm_address_t *coa;
 
678
 
 
679
                if (prefix)
 
680
                        fprintf(fp, prefix);
 
681
                fprintf(fp, "coa ");
 
682
 
 
683
                coa = (xfrm_address_t *)RTA_DATA(tb[XFRMA_COADDR]);
 
684
 
 
685
                if (RTA_PAYLOAD(tb[XFRMA_COADDR]) < sizeof(*coa)) {
 
686
                        fprintf(fp, "(ERROR truncated)");
 
687
                        fprintf(fp, "%s", _SL_);
 
688
                        return;
 
689
                }
 
690
 
 
691
                memset(abuf, '\0', sizeof(abuf));
 
692
                fprintf(fp, "%s",
 
693
                        rt_addr_n2a(family, sizeof(*coa), coa,
 
694
                                    abuf, sizeof(abuf)));
 
695
                fprintf(fp, "%s", _SL_);
 
696
        }
 
697
 
 
698
        if (tb[XFRMA_LASTUSED]) {
 
699
                __u64 lastused;
 
700
 
 
701
                if (prefix)
 
702
                        fprintf(fp, prefix);
 
703
                fprintf(fp, "lastused ");
 
704
 
 
705
                if (RTA_PAYLOAD(tb[XFRMA_LASTUSED]) < sizeof(lastused)) {
 
706
                        fprintf(fp, "(ERROR truncated)");
 
707
                        fprintf(fp, "%s", _SL_);
 
708
                        return;
 
709
                }
 
710
 
 
711
                lastused = *(__u64 *)RTA_DATA(tb[XFRMA_LASTUSED]);
 
712
 
 
713
                fprintf(fp, "%s", strxf_time(lastused));
 
714
                fprintf(fp, "%s", _SL_);
 
715
        }
643
716
}
644
717
 
645
718
static int xfrm_selector_iszero(struct xfrm_selector *s)
656
729
                            const char *title)
657
730
{
658
731
        char buf[STRBUF_SIZE];
 
732
        int force_spi = xfrm_xfrmproto_is_ipsec(xsinfo->id.proto);
659
733
 
660
734
        memset(buf, '\0', sizeof(buf));
661
735
 
662
736
        xfrm_id_info_print(&xsinfo->saddr, &xsinfo->id, xsinfo->mode,
663
 
                           xsinfo->reqid, xsinfo->family, 1, fp, prefix,
664
 
                           title);
 
737
                           xsinfo->reqid, xsinfo->family, force_spi, fp,
 
738
                           prefix, title);
665
739
 
666
740
        if (prefix)
667
741
                STRBUF_CAT(buf, prefix);
677
751
                fprintf(fp, "flag ");
678
752
                XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_NOECN, "noecn");
679
753
                XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_DECAP_DSCP, "decap-dscp");
 
754
                XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_WILDRECV, "wildrecv");
680
755
                if (flags)
681
756
                        fprintf(fp, "%x", flags);
682
757
                if (show_stats > 0)
706
781
                            const char *title)
707
782
{
708
783
        char buf[STRBUF_SIZE];
 
784
        __u8 ptype = XFRM_POLICY_TYPE_MAIN;
709
785
 
710
786
        memset(buf, '\0', sizeof(buf));
711
787
 
749
825
        if (show_stats)
750
826
                fprintf(fp, "index %u ", xpinfo->index);
751
827
        fprintf(fp, "priority %u ", xpinfo->priority);
 
828
 
 
829
        fprintf(fp, "ptype ");
 
830
 
 
831
        if (tb[XFRMA_POLICY_TYPE]) {
 
832
                struct xfrm_userpolicy_type *upt;
 
833
 
 
834
                if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt))
 
835
                        fprintf(fp, "(ERROR truncated)");
 
836
 
 
837
                upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
 
838
                ptype = upt->type;
 
839
        }
 
840
 
 
841
        switch (ptype) {
 
842
        case XFRM_POLICY_TYPE_MAIN:
 
843
                fprintf(fp, "main");
 
844
                break;
 
845
        case XFRM_POLICY_TYPE_SUB:
 
846
                fprintf(fp, "sub");
 
847
                break;
 
848
        default:
 
849
                fprintf(fp, "%u", ptype);
 
850
                break;
 
851
        }
 
852
        fprintf(fp, " ");
 
853
 
752
854
        if (show_stats > 0) {
753
855
                fprintf(fp, "share %s ", strxf_share(xpinfo->share));
754
856
                fprintf(fp, "flag 0x%s", strxf_mask8(xpinfo->flags));
854
956
        char **argv = *argvp;
855
957
 
856
958
        if (matches(*argv, "transport") == 0)
857
 
                *mode = 0;
 
959
                *mode = XFRM_MODE_TRANSPORT;
858
960
        else if (matches(*argv, "tunnel") == 0)
859
 
                *mode = 1;
 
961
                *mode = XFRM_MODE_TUNNEL;
 
962
        else if (matches(*argv, "ro") == 0)
 
963
                *mode = XFRM_MODE_ROUTEOPTIMIZATION;
 
964
        else if (matches(*argv, "in_trigger") == 0)
 
965
                *mode = XFRM_MODE_IN_TRIGGER;
 
966
        else if (matches(*argv, "beet") == 0)
 
967
                *mode = XFRM_MODE_BEET;
860
968
        else
861
969
                invarg("\"MODE\" is invalid", *argv);
862
970
 
1011
1119
                switch (sel->proto) {
1012
1120
                case IPPROTO_ICMP:
1013
1121
                case IPPROTO_ICMPV6:
 
1122
                case IPPROTO_MH:
1014
1123
                        break;
1015
1124
                default:
1016
1125
                        fprintf(stderr, "\"type\" and \"code\" are invalid with proto=%s\n", strxf_proto(sel->proto));