unicast.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Copyright (C) 2010-2013 B.A.T.M.A.N. contributors:
  2. *
  3. * Andreas Langer
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA
  18. */
  19. #ifndef _NET_BATMAN_ADV_UNICAST_H_
  20. #define _NET_BATMAN_ADV_UNICAST_H_
  21. #include "packet.h"
  22. #define BATADV_FRAG_TIMEOUT 10000 /* purge frag list entries after time in ms */
  23. #define BATADV_FRAG_BUFFER_SIZE 6 /* number of list elements in buffer */
  24. int batadv_frag_reassemble_skb(struct sk_buff *skb,
  25. struct batadv_priv *bat_priv,
  26. struct sk_buff **new_skb);
  27. void batadv_frag_list_free(struct list_head *head);
  28. int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
  29. struct batadv_hard_iface *hard_iface,
  30. const uint8_t dstaddr[]);
  31. bool batadv_unicast_4addr_prepare_skb(struct batadv_priv *bat_priv,
  32. struct sk_buff *skb,
  33. struct batadv_orig_node *orig_node,
  34. int packet_subtype);
  35. int batadv_unicast_generic_send_skb(struct batadv_priv *bat_priv,
  36. struct sk_buff *skb, int packet_type,
  37. int packet_subtype);
  38. /**
  39. * batadv_unicast_send_skb - send the skb encapsulated in a unicast packet
  40. * @bat_priv: the bat priv with all the soft interface information
  41. * @skb: the payload to send
  42. */
  43. static inline int batadv_unicast_send_skb(struct batadv_priv *bat_priv,
  44. struct sk_buff *skb)
  45. {
  46. return batadv_unicast_generic_send_skb(bat_priv, skb, BATADV_UNICAST,
  47. 0);
  48. }
  49. /**
  50. * batadv_unicast_send_skb - send the skb encapsulated in a unicast4addr packet
  51. * @bat_priv: the bat priv with all the soft interface information
  52. * @skb: the payload to send
  53. * @packet_subtype: the batman 4addr packet subtype to use
  54. */
  55. static inline int batadv_unicast_4addr_send_skb(struct batadv_priv *bat_priv,
  56. struct sk_buff *skb,
  57. int packet_subtype)
  58. {
  59. return batadv_unicast_generic_send_skb(bat_priv, skb,
  60. BATADV_UNICAST_4ADDR,
  61. packet_subtype);
  62. }
  63. static inline int batadv_frag_can_reassemble(const struct sk_buff *skb, int mtu)
  64. {
  65. const struct batadv_unicast_frag_packet *unicast_packet;
  66. int uneven_correction = 0;
  67. unsigned int merged_size;
  68. unicast_packet = (struct batadv_unicast_frag_packet *)skb->data;
  69. if (unicast_packet->flags & BATADV_UNI_FRAG_LARGETAIL) {
  70. if (unicast_packet->flags & BATADV_UNI_FRAG_HEAD)
  71. uneven_correction = 1;
  72. else
  73. uneven_correction = -1;
  74. }
  75. merged_size = (skb->len - sizeof(*unicast_packet)) * 2;
  76. merged_size += sizeof(struct batadv_unicast_packet) + uneven_correction;
  77. return merged_size <= mtu;
  78. }
  79. #endif /* _NET_BATMAN_ADV_UNICAST_H_ */