18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __NET_RTNH_H
38c2ecf20Sopenharmony_ci#define __NET_RTNH_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h>
68c2ecf20Sopenharmony_ci#include <net/netlink.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_cistatic inline int rtnh_ok(const struct rtnexthop *rtnh, int remaining)
98c2ecf20Sopenharmony_ci{
108c2ecf20Sopenharmony_ci	return remaining >= (int)sizeof(*rtnh) &&
118c2ecf20Sopenharmony_ci	       rtnh->rtnh_len >= sizeof(*rtnh) &&
128c2ecf20Sopenharmony_ci	       rtnh->rtnh_len <= remaining;
138c2ecf20Sopenharmony_ci}
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistatic inline struct rtnexthop *rtnh_next(const struct rtnexthop *rtnh,
168c2ecf20Sopenharmony_ci                                         int *remaining)
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci	int totlen = NLA_ALIGN(rtnh->rtnh_len);
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	*remaining -= totlen;
218c2ecf20Sopenharmony_ci	return (struct rtnexthop *) ((char *) rtnh + totlen);
228c2ecf20Sopenharmony_ci}
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic inline struct nlattr *rtnh_attrs(const struct rtnexthop *rtnh)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	return (struct nlattr *) ((char *) rtnh + NLA_ALIGN(sizeof(*rtnh)));
278c2ecf20Sopenharmony_ci}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic inline int rtnh_attrlen(const struct rtnexthop *rtnh)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	return rtnh->rtnh_len - NLA_ALIGN(sizeof(*rtnh));
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#endif
35