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

« back to all changes in this revision

Viewing changes to lib/match.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:
98
98
               (flow->dl_type == htons(ETH_TYPE_RARP))) {
99
99
        memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
100
100
        memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
 
101
    } else if (eth_type_mpls(flow->dl_type)) {
 
102
        memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
101
103
    }
102
104
 
103
105
    if (flow->dl_type == htons(ETH_TYPE_ARP) ||
109
111
    if (is_ip_any(flow)) {
110
112
        memset(&wc->masks.nw_tos, 0xff, sizeof wc->masks.nw_tos);
111
113
        memset(&wc->masks.nw_ttl, 0xff, sizeof wc->masks.nw_ttl);
112
 
    }
113
 
 
114
 
    if (flow->nw_frag) {
115
 
        memset(&wc->masks.nw_frag, 0xff, sizeof wc->masks.nw_frag);
116
 
    }
117
 
 
118
 
    if (flow->nw_proto == IPPROTO_ICMP || flow->nw_proto == IPPROTO_ICMPV6 ||
119
 
        (flow->tp_src || flow->tp_dst)) {
120
 
        memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
121
 
        memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
122
 
    }
123
 
 
124
 
    if (flow->nw_proto == IPPROTO_ICMPV6) {
125
 
        memset(&wc->masks.arp_sha, 0xff, sizeof wc->masks.arp_sha);
126
 
        memset(&wc->masks.arp_tha, 0xff, sizeof wc->masks.arp_tha);
 
114
 
 
115
        if (flow->nw_frag) {
 
116
            memset(&wc->masks.nw_frag, 0xff, sizeof wc->masks.nw_frag);
 
117
        }
 
118
 
 
119
        if (flow->nw_proto == IPPROTO_ICMP ||
 
120
            flow->nw_proto == IPPROTO_ICMPV6 ||
 
121
            (flow->tp_src || flow->tp_dst)) {
 
122
            memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
 
123
            memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
 
124
        }
 
125
 
 
126
        if (flow->nw_proto == IPPROTO_ICMPV6) {
 
127
            memset(&wc->masks.arp_sha, 0xff, sizeof wc->masks.arp_sha);
 
128
            memset(&wc->masks.arp_tha, 0xff, sizeof wc->masks.arp_tha);
 
129
        }
127
130
    }
128
131
 
129
132
    return;
133
136
void
134
137
match_init_exact(struct match *match, const struct flow *flow)
135
138
{
136
 
    ovs_be64 tun_id = flow->tunnel.tun_id;
137
 
 
138
139
    match->flow = *flow;
139
140
    match->flow.skb_priority = 0;
140
141
    match->flow.skb_mark = 0;
141
 
    memset(&match->flow.tunnel, 0, sizeof match->flow.tunnel);
142
 
    match->flow.tunnel.tun_id = tun_id;
143
142
    flow_wildcards_init_exact(&match->wc);
144
143
}
145
144
 
273
272
}
274
273
 
275
274
void
276
 
match_set_in_port(struct match *match, uint16_t ofp_port)
 
275
match_set_in_port(struct match *match, ofp_port_t ofp_port)
277
276
{
278
 
    match->wc.masks.in_port = UINT16_MAX;
279
 
    match->flow.in_port = ofp_port;
 
277
    match->wc.masks.in_port.ofp_port = u16_to_ofp(UINT16_MAX);
 
278
    match->flow.in_port.ofp_port = ofp_port;
280
279
}
281
280
 
282
281
void
460
459
    match->wc.masks.vlan_tci |= htons(VLAN_CFI | VLAN_PCP_MASK);
461
460
}
462
461
 
 
462
/* Modifies 'match' so that the MPLS label is wildcarded. */
 
463
void
 
464
match_set_any_mpls_label(struct match *match)
 
465
{
 
466
    match->wc.masks.mpls_lse &= ~htonl(MPLS_LABEL_MASK);
 
467
    flow_set_mpls_label(&match->flow, htonl(0));
 
468
}
 
469
 
 
470
/* Modifies 'match' so that it matches only packets with an MPLS header whose
 
471
 * label equals the low 20 bits of 'mpls_label'. */
 
472
void
 
473
match_set_mpls_label(struct match *match, ovs_be32 mpls_label)
 
474
{
 
475
    match->wc.masks.mpls_lse |= htonl(MPLS_LABEL_MASK);
 
476
    flow_set_mpls_label(&match->flow, mpls_label);
 
477
}
 
478
 
 
479
/* Modifies 'match' so that the MPLS TC is wildcarded. */
 
480
void
 
481
match_set_any_mpls_tc(struct match *match)
 
482
{
 
483
    match->wc.masks.mpls_lse &= ~htonl(MPLS_TC_MASK);
 
484
    flow_set_mpls_tc(&match->flow, 0);
 
485
}
 
486
 
 
487
/* Modifies 'match' so that it matches only packets with an MPLS header whose
 
488
 * Traffic Class equals the low 3 bits of 'mpls_tc'. */
 
489
void
 
490
match_set_mpls_tc(struct match *match, uint8_t mpls_tc)
 
491
{
 
492
    match->wc.masks.mpls_lse |= htonl(MPLS_TC_MASK);
 
493
    flow_set_mpls_tc(&match->flow, mpls_tc);
 
494
}
 
495
 
 
496
/* Modifies 'match' so that the MPLS stack flag is wildcarded. */
 
497
void
 
498
match_set_any_mpls_bos(struct match *match)
 
499
{
 
500
    match->wc.masks.mpls_lse &= ~htonl(MPLS_BOS_MASK);
 
501
    flow_set_mpls_bos(&match->flow, 0);
 
502
}
 
503
 
 
504
/* Modifies 'match' so that it matches only packets with an MPLS header whose
 
505
 * Stack Flag equals the lower bit of 'mpls_bos' */
 
506
void
 
507
match_set_mpls_bos(struct match *match, uint8_t mpls_bos)
 
508
{
 
509
    match->wc.masks.mpls_lse |= htonl(MPLS_BOS_MASK);
 
510
    flow_set_mpls_bos(&match->flow, mpls_bos);
 
511
}
 
512
 
463
513
void
464
514
match_set_tp_src(struct match *match, ovs_be16 tp_src)
465
515
{
780
830
 
781
831
    int i;
782
832
 
783
 
    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 18);
 
833
    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 20);
784
834
 
785
835
    if (priority != OFP_DEFAULT_PRIORITY) {
786
836
        ds_put_format(s, "priority=%u,", priority);
832
882
            ds_put_cstr(s, "arp,");
833
883
        } else if (f->dl_type == htons(ETH_TYPE_RARP)) {
834
884
            ds_put_cstr(s, "rarp,");
 
885
        } else if (f->dl_type == htons(ETH_TYPE_MPLS)) {
 
886
            ds_put_cstr(s, "mpls,");
 
887
        } else if (f->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
 
888
            ds_put_cstr(s, "mplsm,");
835
889
        } else {
836
890
            skip_type = false;
837
891
        }
863
917
                      ntohll(f->metadata), ntohll(wc->masks.metadata));
864
918
        break;
865
919
    }
866
 
    if (wc->masks.in_port) {
 
920
    if (wc->masks.in_port.ofp_port) {
867
921
        ds_put_cstr(s, "in_port=");
868
 
        ofputil_format_port(f->in_port, s);
 
922
        ofputil_format_port(f->in_port.ofp_port, s);
869
923
        ds_put_char(s, ',');
870
924
    }
871
925
    if (wc->masks.vlan_tci) {
940
994
    if (wc->masks.nw_ttl) {
941
995
        ds_put_format(s, "nw_ttl=%"PRIu8",", f->nw_ttl);
942
996
    }
 
997
    if (wc->masks.mpls_lse & htonl(MPLS_LABEL_MASK)) {
 
998
        ds_put_format(s, "mpls_label=%"PRIu32",",
 
999
                 mpls_lse_to_label(f->mpls_lse));
 
1000
    }
 
1001
    if (wc->masks.mpls_lse & htonl(MPLS_TC_MASK)) {
 
1002
        ds_put_format(s, "mpls_tc=%"PRIu8",",
 
1003
                 mpls_lse_to_tc(f->mpls_lse));
 
1004
    }
 
1005
    if (wc->masks.mpls_lse & htonl(MPLS_TTL_MASK)) {
 
1006
        ds_put_format(s, "mpls_ttl=%"PRIu8",",
 
1007
                 mpls_lse_to_ttl(f->mpls_lse));
 
1008
    }
 
1009
    if (wc->masks.mpls_lse & htonl(MPLS_BOS_MASK)) {
 
1010
        ds_put_format(s, "mpls_bos=%"PRIu8",",
 
1011
                 mpls_lse_to_bos(f->mpls_lse));
 
1012
    }
943
1013
    switch (wc->masks.nw_frag) {
944
1014
    case FLOW_NW_FRAG_ANY | FLOW_NW_FRAG_LATER:
945
1015
        ds_put_format(s, "nw_frag=%s,",