2 * Copyright (c) 2015 Cloudbase Solutions Srl
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 #define FLOW_MAX_MPLS_LABELS 3
29 #define MPLS_BOS_MASK 0x00000100
31 /* Reference: RFC 5462, RFC 3032
34 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * | Label | TC |S| TTL |
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * Label: Label Value, 20 bits
40 * TC: Traffic Class field, 3 bits
41 * S: Bottom of Stack, 1 bit
42 * TTL: Time to Live, 8 bits
45 typedef struct MPLSHdr {
50 OvsEthertypeIsMpls(ovs_be16 ethertype)
52 return ethertype == htons(ETH_TYPE_MPLS) ||
53 ethertype == htons(ETH_TYPE_MPLS_MCAST);
56 /* Returns the number of MPLS LSEs present in 'a'
58 * Counts 'flow''s MPLS label stack entries (LESs) stopping at the first
59 * entry that has the bottom of stack (BOS) bit set. If no such entry exists,
60 * then zero is returned, meaning that the maximum number of supported
64 OvsCountMplsLabels(PNL_ATTR a)
66 const MPLSHdr *mpls = NlAttrGet(a);
70 for (count = 0; count < FLOW_MAX_MPLS_LABELS; count++) {
71 if ((mpls + count)->lse & htonl(MPLS_BOS_MASK)) {
77 return bos ? ++count : 0;
80 #endif /* __MPLS_H_ */