~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to lib/meta-flow.c

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "dynamic-string.h"
28
28
#include "ofp-errors.h"
29
29
#include "ofp-util.h"
 
30
#include "ovs-thread.h"
30
31
#include "packets.h"
31
32
#include "random.h"
32
33
#include "shash.h"
57
58
    }, {
58
59
        MFF_TUN_SRC, "tun_src", NULL,
59
60
        MF_FIELD_SIZES(be32),
60
 
        MFM_NONE,
 
61
        MFM_FULLY,
61
62
        MFS_IPV4,
62
63
        MFP_NONE,
63
 
        false,
64
 
        0, NULL,
65
 
        0, NULL,
 
64
        true,
 
65
        NXM_NX_TUN_IPV4_SRC, "NXM_NX_TUN_IPV4_SRC",
 
66
        NXM_NX_TUN_IPV4_SRC, "NXM_NX_TUN_IPV4_SRC",
66
67
    }, {
67
68
        MFF_TUN_DST, "tun_dst", NULL,
68
69
        MF_FIELD_SIZES(be32),
69
 
        MFM_NONE,
 
70
        MFM_FULLY,
70
71
        MFS_IPV4,
71
72
        MFP_NONE,
72
 
        false,
73
 
        0, NULL,
74
 
        0, NULL,
 
73
        true,
 
74
        NXM_NX_TUN_IPV4_DST, "NXM_NX_TUN_IPV4_DST",
 
75
        NXM_NX_TUN_IPV4_DST, "NXM_NX_TUN_IPV4_DST",
75
76
    }, {
76
77
        MFF_TUN_FLAGS, "tun_flags", NULL,
77
78
        MF_FIELD_SIZES(be16),
114
115
        MFM_NONE,
115
116
        MFS_OFP_PORT,
116
117
        MFP_NONE,
117
 
        false,
118
 
        NXM_OF_IN_PORT, "NXM_OF_IN_PORT",
 
118
        true,
 
119
        NXM_OF_IN_PORT, "NXM_OF_IN_PORT",
 
120
        NXM_OF_IN_PORT, "NXM_OF_IN_PORT",
 
121
    }, {
 
122
        MFF_IN_PORT_OXM, "in_port_oxm", NULL,
 
123
        MF_FIELD_SIZES(be32),
 
124
        MFM_NONE,
 
125
        MFS_OFP_PORT_OXM,
 
126
        MFP_NONE,
 
127
        true,
 
128
        OXM_OF_IN_PORT, "OXM_OF_IN_PORT",
119
129
        OXM_OF_IN_PORT, "OXM_OF_IN_PORT",
120
130
    }, {
121
131
        MFF_SKB_PRIORITY, "skb_priority", NULL,
256
266
        OXM_OF_VLAN_PCP, "OXM_OF_VLAN_PCP",
257
267
    },
258
268
 
 
269
    /* ## ---- ## */
 
270
    /* ## L2.5 ## */
 
271
    /* ## ---- ## */
 
272
    {
 
273
        MFF_MPLS_LABEL, "mpls_label", NULL,
 
274
        4, 20,
 
275
        MFM_NONE,
 
276
        MFS_DECIMAL,
 
277
        MFP_MPLS,
 
278
        true,
 
279
        OXM_OF_MPLS_LABEL, "OXM_OF_MPLS_LABEL",
 
280
        OXM_OF_MPLS_LABEL, "OXM_OF_MPLS_LABEL",
 
281
    }, {
 
282
        MFF_MPLS_TC, "mpls_tc", NULL,
 
283
        1, 3,
 
284
        MFM_NONE,
 
285
        MFS_DECIMAL,
 
286
        MFP_MPLS,
 
287
        true,
 
288
        OXM_OF_MPLS_TC, "OXM_OF_MPLS_TC",
 
289
        OXM_OF_MPLS_TC, "OXM_OF_MPLS_TC",
 
290
    }, {
 
291
        MFF_MPLS_BOS, "mpls_bos", NULL,
 
292
        1, 1,
 
293
        MFM_NONE,
 
294
        MFS_DECIMAL,
 
295
        MFP_MPLS,
 
296
        false,
 
297
        OXM_OF_MPLS_BOS, "OXM_OF_MPLS_BOS",
 
298
        OXM_OF_MPLS_BOS, "OXM_OF_MPLS_BOS",
 
299
    },
 
300
 
259
301
    /* ## -- ## */
260
302
    /* ## L3 ## */
261
303
    /* ## -- ## */
327
369
        MFP_IP_ANY,
328
370
        true,
329
371
        NXM_OF_IP_TOS, "NXM_OF_IP_TOS",
 
372
        NXM_OF_IP_TOS, "NXM_OF_IP_TOS",
 
373
    }, {
 
374
        MFF_IP_DSCP_SHIFTED, "nw_tos_shifted", NULL,
 
375
        MF_FIELD_SIZES(u8),
 
376
        MFM_NONE,
 
377
        MFS_DECIMAL,
 
378
        MFP_IP_ANY,
 
379
        true,
 
380
        OXM_OF_IP_DSCP, "OXM_OF_IP_DSCP",
330
381
        OXM_OF_IP_DSCP, "OXM_OF_IP_DSCP",
331
382
    }, {
332
383
        MFF_IP_ECN, "nw_ecn", NULL,
530
581
};
531
582
 
532
583
/* Contains 'struct nxm_field's. */
533
 
static struct hmap all_fields = HMAP_INITIALIZER(&all_fields);
 
584
static struct hmap all_fields;
 
585
 
 
586
/* Maps from an mf_field's 'name' or 'extra_name' to the mf_field. */
 
587
static struct shash mf_by_name;
534
588
 
535
589
/* Rate limit for parse errors.  These always indicate a bug in an OpenFlow
536
590
 * controller and so there's not much point in showing a lot of them. */
537
591
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
538
592
 
539
593
const struct mf_field *mf_from_nxm_header__(uint32_t header);
 
594
static void nxm_init(void);
540
595
 
541
596
/* Returns the field with the given 'id'. */
542
597
const struct mf_field *
551
606
const struct mf_field *
552
607
mf_from_name(const char *name)
553
608
{
554
 
    static struct shash mf_by_name = SHASH_INITIALIZER(&mf_by_name);
555
 
 
556
 
    if (shash_is_empty(&mf_by_name)) {
557
 
        const struct mf_field *mf;
558
 
 
559
 
        for (mf = mf_fields; mf < &mf_fields[MFF_N_IDS]; mf++) {
560
 
            shash_add_once(&mf_by_name, mf->name, mf);
561
 
            if (mf->extra_name) {
562
 
                shash_add_once(&mf_by_name, mf->extra_name, mf);
563
 
            }
564
 
        }
565
 
    }
566
 
 
 
609
    nxm_init();
567
610
    return shash_find_data(&mf_by_name, name);
568
611
}
569
612
 
591
634
}
592
635
 
593
636
static void
594
 
nxm_init(void)
 
637
nxm_do_init(void)
595
638
{
596
639
    const struct mf_field *mf;
597
640
 
 
641
    hmap_init(&all_fields);
 
642
    shash_init(&mf_by_name);
598
643
    for (mf = mf_fields; mf < &mf_fields[MFF_N_IDS]; mf++) {
599
644
        nxm_init_add_field(mf, mf->nxm_header);
600
645
        if (mf->oxm_header != mf->nxm_header) {
601
646
            nxm_init_add_field(mf, mf->oxm_header);
602
647
        }
 
648
 
 
649
        shash_add_once(&mf_by_name, mf->name, mf);
 
650
        if (mf->extra_name) {
 
651
            shash_add_once(&mf_by_name, mf->extra_name, mf);
 
652
        }
603
653
    }
604
654
}
605
655
 
 
656
static void
 
657
nxm_init(void)
 
658
{
 
659
    static pthread_once_t once = PTHREAD_ONCE_INIT;
 
660
    pthread_once(&once, nxm_do_init);
 
661
}
 
662
 
606
663
const struct mf_field *
607
664
mf_from_nxm_header(uint32_t header)
608
665
{
609
 
    if (hmap_is_empty(&all_fields)) {
610
 
        nxm_init();
611
 
    }
 
666
    nxm_init();
612
667
    return mf_from_nxm_header__(header);
613
668
}
614
669
 
635
690
mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc)
636
691
{
637
692
    switch (mf->id) {
638
 
    case MFF_TUN_ID:
639
693
    case MFF_TUN_SRC:
 
694
        return !wc->masks.tunnel.ip_src;
640
695
    case MFF_TUN_DST:
 
696
        return !wc->masks.tunnel.ip_dst;
 
697
    case MFF_TUN_ID:
641
698
    case MFF_TUN_TOS:
642
699
    case MFF_TUN_TTL:
643
700
    case MFF_TUN_FLAGS:
645
702
    case MFF_METADATA:
646
703
        return !wc->masks.metadata;
647
704
    case MFF_IN_PORT:
648
 
        return !wc->masks.in_port;
 
705
    case MFF_IN_PORT_OXM:
 
706
        return !wc->masks.in_port.ofp_port;
649
707
    case MFF_SKB_PRIORITY:
650
708
        return !wc->masks.skb_priority;
651
709
    case MFF_SKB_MARK:
678
736
    case MFF_VLAN_PCP:
679
737
        return !(wc->masks.vlan_tci & htons(VLAN_PCP_MASK));
680
738
 
 
739
    case MFF_MPLS_LABEL:
 
740
        return !(wc->masks.mpls_lse & htonl(MPLS_LABEL_MASK));
 
741
    case MFF_MPLS_TC:
 
742
        return !(wc->masks.mpls_lse & htonl(MPLS_TC_MASK));
 
743
    case MFF_MPLS_BOS:
 
744
        return !(wc->masks.mpls_lse & htonl(MPLS_BOS_MASK));
 
745
 
681
746
    case MFF_IPV4_SRC:
682
747
        return !wc->masks.nw_src;
683
748
    case MFF_IPV4_DST:
694
759
    case MFF_IP_PROTO:
695
760
        return !wc->masks.nw_proto;
696
761
    case MFF_IP_DSCP:
 
762
    case MFF_IP_DSCP_SHIFTED:
697
763
        return !(wc->masks.nw_tos & IP_DSCP_MASK);
698
764
    case MFF_IP_ECN:
699
765
        return !(wc->masks.nw_tos & IP_ECN_MASK);
791
857
        return flow->dl_type == htons(ETH_TYPE_IPV6);
792
858
    case MFP_VLAN_VID:
793
859
        return (flow->vlan_tci & htons(VLAN_CFI)) != 0;
 
860
    case MFP_MPLS:
 
861
        return eth_type_mpls(flow->dl_type);
794
862
    case MFP_IP_ANY:
795
863
        return is_ip_any(flow);
796
864
 
873
941
    case MFF_ND_TLL:
874
942
        return true;
875
943
 
 
944
    case MFF_IN_PORT_OXM: {
 
945
        ofp_port_t port;
 
946
        return !ofputil_port_from_ofp11(value->be32, &port);
 
947
    }
 
948
 
876
949
    case MFF_IP_DSCP:
877
950
        return !(value->u8 & ~IP_DSCP_MASK);
 
951
    case MFF_IP_DSCP_SHIFTED:
 
952
        return !(value->u8 & (~IP_DSCP_MASK >> 2));
878
953
    case MFF_IP_ECN:
879
954
        return !(value->u8 & ~IP_ECN_MASK);
880
955
    case MFF_IP_FRAG:
895
970
    case MFF_IPV6_LABEL:
896
971
        return !(value->be32 & ~htonl(IPV6_LABEL_MASK));
897
972
 
 
973
    case MFF_MPLS_LABEL:
 
974
        return !(value->be32 & ~htonl(MPLS_LABEL_MASK >> MPLS_LABEL_SHIFT));
 
975
 
 
976
    case MFF_MPLS_TC:
 
977
        return !(value->u8 & ~(MPLS_TC_MASK >> MPLS_TC_SHIFT));
 
978
 
 
979
    case MFF_MPLS_BOS:
 
980
        return !(value->u8 & ~(MPLS_BOS_MASK >> MPLS_BOS_SHIFT));
 
981
 
898
982
    case MFF_N_IDS:
899
983
    default:
900
984
        NOT_REACHED();
932
1016
        break;
933
1017
 
934
1018
    case MFF_IN_PORT:
935
 
        value->be16 = htons(flow->in_port);
 
1019
        value->be16 = htons(ofp_to_u16(flow->in_port.ofp_port));
 
1020
        break;
 
1021
    case MFF_IN_PORT_OXM:
 
1022
        value->be32 = ofputil_port_to_ofp11(flow->in_port.ofp_port);
936
1023
        break;
937
1024
 
938
1025
    case MFF_SKB_PRIORITY:
975
1062
        value->u8 = vlan_tci_to_pcp(flow->vlan_tci);
976
1063
        break;
977
1064
 
 
1065
    case MFF_MPLS_LABEL:
 
1066
        value->be32 = htonl(mpls_lse_to_label(flow->mpls_lse));
 
1067
        break;
 
1068
 
 
1069
    case MFF_MPLS_TC:
 
1070
        value->u8 = mpls_lse_to_tc(flow->mpls_lse);
 
1071
        break;
 
1072
 
 
1073
    case MFF_MPLS_BOS:
 
1074
        value->u8 = mpls_lse_to_bos(flow->mpls_lse);
 
1075
        break;
 
1076
 
978
1077
    case MFF_IPV4_SRC:
979
1078
        value->be32 = flow->nw_src;
980
1079
        break;
1003
1102
        value->u8 = flow->nw_tos & IP_DSCP_MASK;
1004
1103
        break;
1005
1104
 
 
1105
    case MFF_IP_DSCP_SHIFTED:
 
1106
        value->u8 = flow->nw_tos >> 2;
 
1107
        break;
 
1108
 
1006
1109
    case MFF_IP_ECN:
1007
1110
        value->u8 = flow->nw_tos & IP_ECN_MASK;
1008
1111
        break;
1099
1202
        break;
1100
1203
 
1101
1204
    case MFF_IN_PORT:
1102
 
        match_set_in_port(match, ntohs(value->be16));
1103
 
        break;
 
1205
        match_set_in_port(match, u16_to_ofp(ntohs(value->be16)));
 
1206
        break;
 
1207
 
 
1208
    case MFF_IN_PORT_OXM: {
 
1209
        ofp_port_t port;
 
1210
        ofputil_port_from_ofp11(value->be32, &port);
 
1211
        match_set_in_port(match, port);
 
1212
        break;
 
1213
    }
1104
1214
 
1105
1215
    case MFF_SKB_PRIORITY:
1106
1216
        match_set_skb_priority(match, ntohl(value->be32));
1142
1252
        match_set_dl_vlan_pcp(match, value->u8);
1143
1253
        break;
1144
1254
 
 
1255
    case MFF_MPLS_LABEL:
 
1256
        match_set_mpls_label(match, value->be32);
 
1257
        break;
 
1258
 
 
1259
    case MFF_MPLS_TC:
 
1260
        match_set_mpls_tc(match, value->u8);
 
1261
        break;
 
1262
 
 
1263
    case MFF_MPLS_BOS:
 
1264
        match_set_mpls_bos(match, value->u8);
 
1265
        break;
 
1266
 
1145
1267
    case MFF_IPV4_SRC:
1146
1268
        match_set_nw_src(match, value->be32);
1147
1269
        break;
1170
1292
        match_set_nw_dscp(match, value->u8);
1171
1293
        break;
1172
1294
 
 
1295
    case MFF_IP_DSCP_SHIFTED:
 
1296
        match_set_nw_dscp(match, value->u8 << 2);
 
1297
        break;
 
1298
 
1173
1299
    case MFF_IP_ECN:
1174
1300
        match_set_nw_ecn(match, value->u8);
1175
1301
        break;
1234
1360
    }
1235
1361
}
1236
1362
 
1237
 
/* Makes 'match' match field 'mf' exactly, with the value matched taken from
1238
 
 * 'value'.  The caller is responsible for ensuring that 'match' meets 'mf''s
1239
 
 * prerequisites. */
 
1363
/* Sets 'flow' member field described by 'mf' to 'value'.  The caller is
 
1364
 * responsible for ensuring that 'flow' meets 'mf''s prerequisites.*/
1240
1365
void
1241
1366
mf_set_flow_value(const struct mf_field *mf,
1242
1367
                  const union mf_value *value, struct flow *flow)
1266
1391
        break;
1267
1392
 
1268
1393
    case MFF_IN_PORT:
1269
 
        flow->in_port = ntohs(value->be16);
1270
 
        break;
 
1394
        flow->in_port.ofp_port = u16_to_ofp(ntohs(value->be16));
 
1395
        break;
 
1396
 
 
1397
    case MFF_IN_PORT_OXM: {
 
1398
        ofp_port_t port;
 
1399
        ofputil_port_from_ofp11(value->be32, &port);
 
1400
        flow->in_port.ofp_port = port;
 
1401
        break;
 
1402
    }
1271
1403
 
1272
1404
    case MFF_SKB_PRIORITY:
1273
1405
        flow->skb_priority = ntohl(value->be32);
1309
1441
        flow_set_vlan_pcp(flow, value->u8);
1310
1442
        break;
1311
1443
 
 
1444
    case MFF_MPLS_LABEL:
 
1445
        flow_set_mpls_label(flow, value->be32);
 
1446
        break;
 
1447
 
 
1448
    case MFF_MPLS_TC:
 
1449
        flow_set_mpls_tc(flow, value->u8);
 
1450
        break;
 
1451
 
 
1452
    case MFF_MPLS_BOS:
 
1453
        flow_set_mpls_bos(flow, value->u8);
 
1454
        break;
 
1455
 
1312
1456
    case MFF_IPV4_SRC:
1313
1457
        flow->nw_src = value->be32;
1314
1458
        break;
1338
1482
        flow->nw_tos |= value->u8 & IP_DSCP_MASK;
1339
1483
        break;
1340
1484
 
 
1485
    case MFF_IP_DSCP_SHIFTED:
 
1486
        flow->nw_tos &= ~IP_DSCP_MASK;
 
1487
        flow->nw_tos |= value->u8 << 2;
 
1488
        break;
 
1489
 
1341
1490
    case MFF_IP_ECN:
1342
1491
        flow->nw_tos &= ~IP_ECN_MASK;
1343
1492
        flow->nw_tos |= value->u8 & IP_ECN_MASK;
1448
1597
        break;
1449
1598
 
1450
1599
    case MFF_IN_PORT:
1451
 
        match->flow.in_port = 0;
1452
 
        match->wc.masks.in_port = 0;
 
1600
    case MFF_IN_PORT_OXM:
 
1601
        match->flow.in_port.ofp_port = 0;
 
1602
        match->wc.masks.in_port.ofp_port = 0;
1453
1603
        break;
1454
1604
 
1455
1605
    case MFF_SKB_PRIORITY:
1495
1645
        match_set_any_pcp(match);
1496
1646
        break;
1497
1647
 
 
1648
    case MFF_MPLS_LABEL:
 
1649
        match_set_any_mpls_label(match);
 
1650
        break;
 
1651
 
 
1652
    case MFF_MPLS_TC:
 
1653
        match_set_any_mpls_tc(match);
 
1654
        break;
 
1655
 
 
1656
    case MFF_MPLS_BOS:
 
1657
        match_set_any_mpls_bos(match);
 
1658
        break;
 
1659
 
1498
1660
    case MFF_IPV4_SRC:
1499
1661
    case MFF_ARP_SPA:
1500
1662
        match_set_nw_src_masked(match, htonl(0), htonl(0));
1526
1688
        break;
1527
1689
 
1528
1690
    case MFF_IP_DSCP:
 
1691
    case MFF_IP_DSCP_SHIFTED:
1529
1692
        match->wc.masks.nw_tos &= ~IP_DSCP_MASK;
1530
1693
        match->flow.nw_tos &= ~IP_DSCP_MASK;
1531
1694
        break;
1616
1779
 
1617
1780
    switch (mf->id) {
1618
1781
    case MFF_IN_PORT:
 
1782
    case MFF_IN_PORT_OXM:
1619
1783
    case MFF_SKB_MARK:
1620
1784
    case MFF_SKB_PRIORITY:
1621
1785
    case MFF_ETH_TYPE:
1622
1786
    case MFF_DL_VLAN:
1623
1787
    case MFF_DL_VLAN_PCP:
1624
1788
    case MFF_VLAN_PCP:
 
1789
    case MFF_MPLS_LABEL:
 
1790
    case MFF_MPLS_TC:
 
1791
    case MFF_MPLS_BOS:
1625
1792
    case MFF_IP_PROTO:
1626
1793
    case MFF_IP_TTL:
1627
1794
    case MFF_IP_DSCP:
 
1795
    case MFF_IP_DSCP_SHIFTED:
1628
1796
    case MFF_IP_ECN:
1629
1797
    case MFF_ARP_OP:
1630
1798
    case MFF_ICMPV4_TYPE:
1847
2015
    case MFF_ND_TLL:
1848
2016
        break;
1849
2017
 
 
2018
    case MFF_IN_PORT_OXM:
 
2019
        value->be32 = ofputil_port_to_ofp11(u16_to_ofp(ntohs(value->be16)));
 
2020
        break;
 
2021
 
1850
2022
    case MFF_IPV6_LABEL:
1851
2023
        value->be32 &= ~htonl(IPV6_LABEL_MASK);
1852
2024
        break;
1855
2027
        value->u8 &= IP_DSCP_MASK;
1856
2028
        break;
1857
2029
 
 
2030
    case MFF_IP_DSCP_SHIFTED:
 
2031
        value->u8 &= IP_DSCP_MASK >> 2;
 
2032
        break;
 
2033
 
1858
2034
    case MFF_IP_ECN:
1859
2035
        value->u8 &= IP_ECN_MASK;
1860
2036
        break;
1879
2055
        value->u8 &= 0x07;
1880
2056
        break;
1881
2057
 
 
2058
    case MFF_MPLS_LABEL:
 
2059
        value->be32 &= htonl(MPLS_LABEL_MASK >> MPLS_LABEL_SHIFT);
 
2060
        break;
 
2061
 
 
2062
    case MFF_MPLS_TC:
 
2063
        value->u8 &= MPLS_TC_MASK >> MPLS_TC_SHIFT;
 
2064
        break;
 
2065
 
 
2066
    case MFF_MPLS_BOS:
 
2067
        value->u8 &= MPLS_BOS_MASK >> MPLS_BOS_SHIFT;
 
2068
        break;
 
2069
 
1882
2070
    case MFF_N_IDS:
1883
2071
    default:
1884
2072
        NOT_REACHED();
2019
2207
mf_from_ofp_port_string(const struct mf_field *mf, const char *s,
2020
2208
                        ovs_be16 *valuep, ovs_be16 *maskp)
2021
2209
{
2022
 
    uint16_t port;
 
2210
    ofp_port_t port;
2023
2211
 
2024
2212
    ovs_assert(mf->n_bytes == sizeof(ovs_be16));
2025
 
    if (*s == '-') {
2026
 
        return xasprintf("%s: negative values not supported for %s",
2027
 
                         s, mf->name);
2028
 
    } else if (ofputil_port_from_string(s, &port)) {
2029
 
        *valuep = htons(port);
 
2213
 
 
2214
    if (ofputil_port_from_string(s, &port)) {
 
2215
        *valuep = htons(ofp_to_u16(port));
2030
2216
        *maskp = htons(UINT16_MAX);
2031
2217
        return NULL;
2032
 
    } else {
2033
 
        return mf_from_integer_string(mf, s,
2034
 
                                      (uint8_t *) valuep, (uint8_t *) maskp);
2035
 
    }
 
2218
    }
 
2219
    return xasprintf("%s: port value out of range for %s", s, mf->name);
 
2220
}
 
2221
 
 
2222
static char *
 
2223
mf_from_ofp_port_string32(const struct mf_field *mf, const char *s,
 
2224
                          ovs_be32 *valuep, ovs_be32 *maskp)
 
2225
{
 
2226
    ofp_port_t port;
 
2227
 
 
2228
    ovs_assert(mf->n_bytes == sizeof(ovs_be32));
 
2229
    if (ofputil_port_from_string(s, &port)) {
 
2230
        *valuep = ofputil_port_to_ofp11(port);
 
2231
        *maskp = htonl(UINT32_MAX);
 
2232
        return NULL;
 
2233
    }
 
2234
    return xasprintf("%s: port value out of range for %s", s, mf->name);
2036
2235
}
2037
2236
 
2038
2237
struct frag_handling {
2172
2371
    case MFS_OFP_PORT:
2173
2372
        return mf_from_ofp_port_string(mf, s, &value->be16, &mask->be16);
2174
2373
 
 
2374
    case MFS_OFP_PORT_OXM:
 
2375
        return mf_from_ofp_port_string32(mf, s, &value->be32, &mask->be32);
 
2376
 
2175
2377
    case MFS_FRAG:
2176
2378
        return mf_from_frag_string(s, &value->u8, &mask->u8);
2177
2379
 
2275
2477
    }
2276
2478
 
2277
2479
    switch (mf->string) {
 
2480
    case MFS_OFP_PORT_OXM:
 
2481
        if (!mask) {
 
2482
            ofp_port_t port;
 
2483
            ofputil_port_from_ofp11(value->be32, &port);
 
2484
            ofputil_format_port(port, s);
 
2485
            break;
 
2486
        }
 
2487
        /* fall through */
2278
2488
    case MFS_OFP_PORT:
2279
2489
        if (!mask) {
2280
 
            ofputil_format_port(ntohs(value->be16), s);
 
2490
            ofputil_format_port(u16_to_ofp(ntohs(value->be16)), s);
2281
2491
            break;
2282
2492
        }
2283
2493
        /* fall through */
2436
2646
 * bit indexes.  "..end" may be omitted to indicate a single bit.  "start..end"
2437
2647
 * may both be omitted (the [] are still required) to indicate an entire
2438
2648
 * field. */
2439
 
char *
 
2649
char * WARN_UNUSED_RESULT
2440
2650
mf_parse_subfield__(struct mf_subfield *sf, const char **sp)
2441
2651
{
2442
2652
    const struct mf_field *field;
2491
2701
    return NULL;
2492
2702
}
2493
2703
 
2494
 
/* Parses a subfield from the beginning of 's' into 'sf'.  Returns the first
2495
 
 * byte in 's' following the parsed string.
2496
 
 *
2497
 
 * Exits with an error message if 's' has incorrect syntax.
 
2704
/* Parses a subfield from the entirety of 's' into 'sf'.  Returns NULL if
 
2705
 * successful, otherwise a malloc()'d string describing the error.  The caller
 
2706
 * is responsible for freeing the returned string.
2498
2707
 *
2499
2708
 * The syntax parsed from 's' takes the form "header[start..end]" where
2500
2709
 * 'header' is the name of an NXM field and 'start' and 'end' are (inclusive)
2501
2710
 * bit indexes.  "..end" may be omitted to indicate a single bit.  "start..end"
2502
2711
 * may both be omitted (the [] are still required) to indicate an entire
2503
2712
 * field.  */
2504
 
const char *
 
2713
char * WARN_UNUSED_RESULT
2505
2714
mf_parse_subfield(struct mf_subfield *sf, const char *s)
2506
2715
{
2507
 
    char *msg = mf_parse_subfield__(sf, &s);
2508
 
    if (msg) {
2509
 
        ovs_fatal(0, "%s", msg);
 
2716
    char *error = mf_parse_subfield__(sf, &s);
 
2717
    if (!error && s[0]) {
 
2718
        error = xstrdup("unexpected input following field syntax");
2510
2719
    }
2511
 
    return s;
 
2720
    return error;
2512
2721
}
2513
2722
 
2514
2723
void