From acbbe986f3895db9914b05f8f6c5bf8f759390f9 Mon Sep 17 00:00:00 2001 From: Greg Goodrich Date: Tue, 17 Sep 2019 14:21:37 -0500 Subject: [PATCH] Added support for debugging (-X) for unexpected input lines --- net/frr/src/opnsense/scripts/quagga/quagga.rb | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/net/frr/src/opnsense/scripts/quagga/quagga.rb b/net/frr/src/opnsense/scripts/quagga/quagga.rb index 8b8661f1e..40a0afe7e 100755 --- a/net/frr/src/opnsense/scripts/quagga/quagga.rb +++ b/net/frr/src/opnsense/scripts/quagga/quagga.rb @@ -394,35 +394,46 @@ class BGP output = output.split("\n") bgp = {} - x,y = output.shift.scan(/.*?version is (\d+).*?ID is ([0-9\.]+).*/).first - bgp['table_version'] = x - bgp['local_router_id'] = y - - # find out, what the status abbreviations mean - status_codes = {} - line = output.shift - line.split(":").last.strip.split(",").each do |x| - k,v = x.strip.split(" ") - status_codes[k] = v - end - while line.end_with? "," - line = output.shift - line.strip.split(",").each do |x| - k,v = x.strip.split(" ") - status_codes[k] = v + # Process the header/definitions + while line = output.shift&.rstrip + case line + when /^BGP table version/ + x,y = line.scan(/.*?version is (\d+).*?ID is ([0-9\.]+).*/).first + bgp['table_version'] = x + bgp['local_router_id'] = y + when /^Status codes/ + # find out, what the status abbreviations mean + status_codes = {} + line.split(":").last.strip.split(",").each do |x| + k,v = x.strip.split(" ") + status_codes[k] = v + end + while line.end_with? "," + line = output.shift + line.strip.split(",").each do |x| + k,v = x.strip.split(" ") + status_codes[k] = v + end + end + when /^Origin codes/ + # same like before but for the origin codes + origin_codes = {} + line.split(":").last.strip.split(",").each do |x| + k,v = x.strip.split(" - ") + origin_codes[k] = v + end + when /^Nexthop codes/ + # Just eat this line, nothing to do with it + when "" + # Found the end of the header, reached the table + break + else + # eat all other (unexpected) lines + puts line if $QUAGGA_DEBUG end end - # same like before but for the origin codes - origin_codes = {} - output.shift.split(":").last.strip.split(",").each do |x| - k,v = x.strip.split(" - ") - origin_codes[k] = v - end - - # drop empty line - output.shift - # read entries + # Process the tabular data bgp['output'] = [] qta = QuaggaTableReader.new(["Network", "Next Hop", "Metric", "LocPrf", "Weight", "Path"]) qta.read_headline(output.shift,true)