@@ -44,7 +44,7 @@ namespace aalwines {
4444 };
4545
4646 enum type_t {
47- ANYMPLS = 1 , ANYIP = 2 , IP4 = 4 , IP6 = 8 , MPLS = 16 , STICKY = 32 , INTERFACE = 64 , NONE = 128 , ANYSTICKY = ANYMPLS | STICKY , STICKY_MPLS = MPLS | STICKY
47+ ANYIP= 2 , IP4 = 4 , IP6 = 8 , MPLS = 16 , STICKY = 32 , INTERFACE = 64 , NONE = 128 , STICKY_MPLS = MPLS | STICKY
4848 };
4949
5050 struct label_t {
@@ -81,26 +81,18 @@ namespace aalwines {
8181 _mask = 64 ;
8282 _value = 0 ;
8383 break ;
84- case ANYSTICKY:
85- case ANYMPLS:
86- _mask = 64 ;
87- _value = 0 ;
88- break ;
8984 case STICKY_MPLS:
9085 case MPLS:
9186 _mask = std::min<uint8_t >(64 , _mask);
92- _value = (_value >> _mask) << _mask;
9387 if (_mask == 64 )
94- {
95- if (_type == STICKY_MPLS)
96- *this = any_sticky_mpls;
97- else
98- *this = any_mpls;
99- }
100-
88+ _value = 0 ;
89+ _value = (_value >> _mask) << _mask;
10190 break ;
10291 case IP4:
103- _mask = std::min<uint8_t >(32 , _mask);
92+ if (_mask >= 32 ) {
93+ _mask = 64 ;
94+ _value = 0 ;
95+ }
10496 _value = std::min<uint64_t >(std::numeric_limits<uint32_t >::max (), _value);
10597 _value = (_value >> _mask) << _mask;
10698 if (_mask >= 32 )
@@ -128,8 +120,9 @@ namespace aalwines {
128120 }
129121
130122 bool uses_mask () const {
131- return _mask != 0 && _type != INTERFACE && _type != ANYIP && _type != ANYMPLS && _type != ANYSTICKY ;
123+ return _mask != 0 && _mask != 64 && _type != INTERFACE && _type != ANYIP ;
132124 }
125+
133126 bool operator <(const label_t & other) const {
134127 if (_type != other._type )
135128 return _type < other._type ;
@@ -166,11 +159,14 @@ namespace aalwines {
166159 case STICKY_MPLS:
167160 stream << " $" ;
168161 case MPLS:
169- stream << ((label._value >> label._mask ) << label._mask );
162+ if (label._mask >= 64 || label == Query::label_t ::unused_mpls || label == Query::label_t ::unused_sticky_mpls)
163+ stream << " mpls" ;
164+ else
165+ stream << ((label._value >> label._mask ) << label._mask );
170166 break ;
171167 case IP4:
172168 mx = 32 ;
173- if (label._mask < 32 )
169+ if (label._mask < 32 && label != Query:: label_t ::unused_ip4 )
174170 write_ip4 (stream, (label._value >> label._mask ) << label._mask );
175171 else
176172 {
@@ -180,7 +176,7 @@ namespace aalwines {
180176 break ;
181177 case IP6:
182178 mx = 64 ;
183- if (label._mask < 64 )
179+ if (label._mask < 64 && label != Query:: label_t ::unused_ip6 )
184180 write_ip6 (stream, (label._value >> label._mask ) << label._mask );
185181 else
186182 {
@@ -194,11 +190,6 @@ namespace aalwines {
194190 case ANYIP:
195191 stream << " ip" ;
196192 break ;
197- case ANYSTICKY:
198- stream << " $" ;
199- case ANYMPLS:
200- stream << " mpls" ;
201- break ;
202193 case NONE:
203194 stream << " NONE" ;
204195 break ;
@@ -216,14 +207,11 @@ namespace aalwines {
216207 if (_type == other._type )
217208 {
218209 auto m = std::max (other._mask , _mask);
210+ if (_mask >= 64 ) return true ;
219211 return (_value >> m) == (other._value >> m);
220212 }
221- if (std::min (_type, other._type ) == ANYIP &&
222- (std::max (other._type , _type) == IP4 || std::max (other._type , _type) == IP6))
223- return true ;
224- if (std::min (_type, other._type ) == ANYMPLS && std::max (_type, other._type ) == MPLS)
225- return true ;
226- if (std::min (_type, other._type ) == ANYSTICKY && std::max (_type, other._type ) == STICKY_MPLS)
213+ if (std::min (_type, other._type ) == ANYIP &&
214+ (std::max (other._type , _type) == IP4 || std::max (other._type , _type) == IP6))
227215 return true ;
228216 return false ;
229217 }
0 commit comments