nexthop.h 865 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NET_NEXTHOP_H
  3. #define __NET_NEXTHOP_H
  4. #include <linux/rtnetlink.h>
  5. #include <net/netlink.h>
  6. static inline int rtnh_ok(const struct rtnexthop *rtnh, int remaining)
  7. {
  8. return remaining >= (int)sizeof(*rtnh) &&
  9. rtnh->rtnh_len >= sizeof(*rtnh) &&
  10. rtnh->rtnh_len <= remaining;
  11. }
  12. static inline struct rtnexthop *rtnh_next(const struct rtnexthop *rtnh,
  13. int *remaining)
  14. {
  15. int totlen = NLA_ALIGN(rtnh->rtnh_len);
  16. *remaining -= totlen;
  17. return (struct rtnexthop *) ((char *) rtnh + totlen);
  18. }
  19. static inline struct nlattr *rtnh_attrs(const struct rtnexthop *rtnh)
  20. {
  21. return (struct nlattr *) ((char *) rtnh + NLA_ALIGN(sizeof(*rtnh)));
  22. }
  23. static inline int rtnh_attrlen(const struct rtnexthop *rtnh)
  24. {
  25. return rtnh->rtnh_len - NLA_ALIGN(sizeof(*rtnh));
  26. }
  27. #endif