13b01bf88STom Jones#- 2*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 33b01bf88STom Jones# 43b01bf88STom Jones# Copyright (c) 2020 Ahsan Barkati 53b01bf88STom Jones# 63b01bf88STom Jones# Redistribution and use in source and binary forms, with or without 73b01bf88STom Jones# modification, are permitted provided that the following conditions 83b01bf88STom Jones# are met: 93b01bf88STom Jones# 1. Redistributions of source code must retain the above copyright 103b01bf88STom Jones# notice, this list of conditions and the following disclaimer. 113b01bf88STom Jones# 2. Redistributions in binary form must reproduce the above copyright 123b01bf88STom Jones# notice, this list of conditions and the following disclaimer in the 133b01bf88STom Jones# documentation and/or other materials provided with the distribution. 143b01bf88STom Jones# 153b01bf88STom Jones# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 163b01bf88STom Jones# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 173b01bf88STom Jones# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 183b01bf88STom Jones# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 193b01bf88STom Jones# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 203b01bf88STom Jones# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 213b01bf88STom Jones# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 223b01bf88STom Jones# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 233b01bf88STom Jones# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 243b01bf88STom Jones# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 253b01bf88STom Jones# SUCH DAMAGE. 263b01bf88STom Jones# 273b01bf88STom Jones# 283b01bf88STom Jones 293b01bf88STom Jones. $(atf_get_srcdir)/../../sys/common/vnet.subr 303b01bf88STom Jones 313b01bf88STom Jonescheck_route() 323b01bf88STom Jones{ 333b01bf88STom Jones jname=$1 343b01bf88STom Jones dest=$2 353b01bf88STom Jones result=$(jexec $jname netstat -r --libxo json) 363b01bf88STom Jones 373b01bf88STom Jones # This query selects the JSON item from the array of rt-entry 383b01bf88STom Jones # for which the destination address is $dest 393b01bf88STom Jones query=".statistics.\"route-information\".\"route-table\".\"rt-family\"[0].\"rt-entry\"[]|select(.destination==\"${dest}\")" 403b01bf88STom Jones 413b01bf88STom Jones # Gateway is then extracted from the JSON item as described above 423b01bf88STom Jones gateway=$(echo $result | jq -r ${query}.gateway) 433b01bf88STom Jones 443b01bf88STom Jones echo ${gateway} 453b01bf88STom Jones} 463b01bf88STom Jones 47