162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef __NET_RTNH_H 362306a36Sopenharmony_ci#define __NET_RTNH_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/rtnetlink.h> 662306a36Sopenharmony_ci#include <net/netlink.h> 762306a36Sopenharmony_ci 862306a36Sopenharmony_cistatic inline int rtnh_ok(const struct rtnexthop *rtnh, int remaining) 962306a36Sopenharmony_ci{ 1062306a36Sopenharmony_ci return remaining >= (int)sizeof(*rtnh) && 1162306a36Sopenharmony_ci rtnh->rtnh_len >= sizeof(*rtnh) && 1262306a36Sopenharmony_ci rtnh->rtnh_len <= remaining; 1362306a36Sopenharmony_ci} 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_cistatic inline struct rtnexthop *rtnh_next(const struct rtnexthop *rtnh, 1662306a36Sopenharmony_ci int *remaining) 1762306a36Sopenharmony_ci{ 1862306a36Sopenharmony_ci int totlen = NLA_ALIGN(rtnh->rtnh_len); 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci *remaining -= totlen; 2162306a36Sopenharmony_ci return (struct rtnexthop *) ((char *) rtnh + totlen); 2262306a36Sopenharmony_ci} 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_cistatic inline struct nlattr *rtnh_attrs(const struct rtnexthop *rtnh) 2562306a36Sopenharmony_ci{ 2662306a36Sopenharmony_ci return (struct nlattr *) ((char *) rtnh + NLA_ALIGN(sizeof(*rtnh))); 2762306a36Sopenharmony_ci} 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_cistatic inline int rtnh_attrlen(const struct rtnexthop *rtnh) 3062306a36Sopenharmony_ci{ 3162306a36Sopenharmony_ci return rtnh->rtnh_len - NLA_ALIGN(sizeof(*rtnh)); 3262306a36Sopenharmony_ci} 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#endif 35