Fix the IPv4RouteParser regular expression

The IPv4RouteParser regular expression fails to match when there is nothing after the interface name like in the following case:
    $ ip route
    default via 10.1.52.1 dev eth0 
    10.1.52.0/23 dev eth0 proto kernel scope link src 10.1.52.148
This commit is contained in:
Sophie Brun 2018-11-23 11:03:13 +01:00 committed by GitHub
commit 47c37c066c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,7 @@ import (
)
// only matches gateway lines
var IPv4RouteParser = regexp.MustCompile(`^(default|[0-9\.]+)\svia\s([0-9\.]+)\sdev\s(\w+)\s.*$`)
var IPv4RouteParser = regexp.MustCompile(`^(default|[0-9\.]+)\svia\s([0-9\.]+)\sdev\s(\w+)(?:\s.*|)$`)
var IPv4RouteTokens = 4
var IPv4RouteCmd = "ip"
var IPv4RouteCmdOpts = []string{"route"}