Skip to content

Commit 6a10da1

Browse files
author
Will Rigby
committed
Add support for MPLS label stack
See RFCs 3954 and 5642 * New class in util.rb for MPLS stack labels * New entries for MPLS stack entries 1-10 * Build an array for the MPLS stack, rather than just putting the raw mpls_label_x fields on the event
1 parent 7377b83 commit 6a10da1

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

lib/logstash/codecs/netflow.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ def decode(payload, &block)
201201

202202
event[@target]['flowset_id'] = record.flowset_id
203203

204+
mpls_stack_ended = false
205+
204206
r.each_pair do |k,v|
205207
case k.to_s
206208
when /_switched$/
@@ -209,6 +211,15 @@ def decode(payload, &block)
209211
# v9 did away with the nanosecs field
210212
micros = 1000000 - (millis % 1000)
211213
event[@target][k.to_s] = Time.at(seconds, micros).utc.strftime("%Y-%m-%dT%H:%M:%S.%3NZ")
214+
when /^mpls_label_\d+$/
215+
event[@target]["mpls_label_stack"] ||= []
216+
unless mpls_stack_ended
217+
event[@target]["mpls_label_stack"] << {
218+
"label" => v.label,
219+
"traffic_class" => v.traffic_class
220+
}
221+
mpls_stack_ended = ! v.end_of_stack.zero?
222+
end
212223
else
213224
event[@target][k.to_s] = v
214225
end

lib/logstash/codecs/netflow/netflow.yaml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
- :uint8
138138
- :mpls_top_label_type
139139
47:
140-
- :uint32
140+
- :ip4_addr
141141
- :mpls_top_label_ip_addr
142142
48:
143143
- 4
@@ -201,6 +201,36 @@
201201
- :skip
202202
69:
203203
- :skip
204+
70:
205+
- :mpls_stack_entry
206+
- :mpls_label_1
207+
71:
208+
- :mpls_stack_entry
209+
- :mpls_label_2
210+
72:
211+
- :mpls_stack_entry
212+
- :mpls_label_3
213+
73:
214+
- :mpls_stack_entry
215+
- :mpls_label_4
216+
74:
217+
- :mpls_stack_entry
218+
- :mpls_label_5
219+
75:
220+
- :mpls_stack_entry
221+
- :mpls_label_6
222+
76:
223+
- :mpls_stack_entry
224+
- :mpls_label_7
225+
77:
226+
- :mpls_stack_entry
227+
- :mpls_label_8
228+
78:
229+
- :mpls_stack_entry
230+
- :mpls_label_9
231+
79:
232+
- :mpls_stack_entry
233+
- :mpls_label_10
204234
80:
205235
- :mac_addr
206236
- :in_dst_mac

lib/logstash/codecs/netflow/util.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ def get
5151
end
5252
end
5353

54+
# The three-bit field was originally labeled 'Experimental',
55+
# but has since been re-named to Traffic Class (see RFC 5642)
56+
class MplsStackEntry < BinData::Record
57+
endian :big
58+
59+
bit20 :label
60+
bit3 :traffic_class
61+
bit1 :end_of_stack
62+
63+
def to_i
64+
self.label
65+
end
66+
67+
def to_s
68+
self.label.to_s
69+
end
70+
end
71+
5472
class Header < BinData::Record
5573
endian :big
5674
uint16 :version

0 commit comments

Comments
 (0)