socket.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
  4. */
  5. #ifndef _WG_SOCKET_H
  6. #define _WG_SOCKET_H
  7. #include <linux/netdevice.h>
  8. #include <linux/udp.h>
  9. #include <linux/if_vlan.h>
  10. #include <linux/if_ether.h>
  11. int wg_socket_init(struct wg_device *wg, u16 port);
  12. void wg_socket_reinit(struct wg_device *wg, struct sock *new4,
  13. struct sock *new6);
  14. int wg_socket_send_buffer_to_peer(struct wg_peer *peer, void *data,
  15. size_t len, u8 ds);
  16. int wg_socket_send_skb_to_peer(struct wg_peer *peer, struct sk_buff *skb,
  17. u8 ds);
  18. int wg_socket_send_buffer_as_reply_to_skb(struct wg_device *wg,
  19. struct sk_buff *in_skb,
  20. void *out_buffer, size_t len);
  21. int wg_socket_endpoint_from_skb(struct endpoint *endpoint,
  22. const struct sk_buff *skb);
  23. void wg_socket_set_peer_endpoint(struct wg_peer *peer,
  24. const struct endpoint *endpoint);
  25. void wg_socket_set_peer_endpoint_from_skb(struct wg_peer *peer,
  26. const struct sk_buff *skb);
  27. void wg_socket_clear_peer_endpoint_src(struct wg_peer *peer);
  28. #if defined(CONFIG_DYNAMIC_DEBUG) || defined(DEBUG)
  29. #define net_dbg_skb_ratelimited(fmt, dev, skb, ...) do { \
  30. struct endpoint __endpoint; \
  31. wg_socket_endpoint_from_skb(&__endpoint, skb); \
  32. net_dbg_ratelimited(fmt, dev, &__endpoint.addr, \
  33. ##__VA_ARGS__); \
  34. } while (0)
  35. #else
  36. #define net_dbg_skb_ratelimited(fmt, skb, ...)
  37. #endif
  38. #endif /* _WG_SOCKET_H */