// 2019 Rackspace, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. package tsip // FindNextHop method will take a ip address as a string input and do a route lookup across // Rackspace infrastructure to gather the next-hop address by pulling the most specific // route. // Return data will be the next-hop address or the self address if not found. func (c *Client) FindNextHop(ipAddr string) (string, error) { s, err := c.u.GetStaticRouteByIP(ipAddr, nil) if err != nil { return ipAddr, err } // If we cannot find any routing information for this address, // return the self address. if s.Count == 0 { return ipAddr, nil } // Return data from Unipede is sorted most specific route first. Because of this, we only // need to return the first iteration that had a next-hop address assigned. for _, dev := range s.Data { if dev.NextHopAddress != "" { return dev.NextHopAddress, nil } } return ipAddr, nil }