ip.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #ifndef _LINUX_IP_H
  16. #define _LINUX_IP_H
  17. /* SOL_IP socket options */
  18. #define IPTOS_TOS_MASK 0x1E
  19. #define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK)
  20. #define IPTOS_LOWDELAY 0x10
  21. #define IPTOS_THROUGHPUT 0x08
  22. #define IPTOS_RELIABILITY 0x04
  23. #define IPTOS_MINCOST 0x02
  24. #define IPTOS_PREC_MASK 0xE0
  25. #define IPTOS_PREC(tos) ((tos)&IPTOS_PREC_MASK)
  26. #define IPTOS_PREC_NETCONTROL 0xe0
  27. #define IPTOS_PREC_INTERNETCONTROL 0xc0
  28. #define IPTOS_PREC_CRITIC_ECP 0xa0
  29. #define IPTOS_PREC_FLASHOVERRIDE 0x80
  30. #define IPTOS_PREC_FLASH 0x60
  31. #define IPTOS_PREC_IMMEDIATE 0x40
  32. #define IPTOS_PREC_PRIORITY 0x20
  33. #define IPTOS_PREC_ROUTINE 0x00
  34. /* IP options */
  35. #define IPOPT_COPY 0x80
  36. #define IPOPT_CLASS_MASK 0x60
  37. #define IPOPT_NUMBER_MASK 0x1f
  38. #define IPOPT_COPIED(o) ((o)&IPOPT_COPY)
  39. #define IPOPT_CLASS(o) ((o)&IPOPT_CLASS_MASK)
  40. #define IPOPT_NUMBER(o) ((o)&IPOPT_NUMBER_MASK)
  41. #define IPOPT_CONTROL 0x00
  42. #define IPOPT_RESERVED1 0x20
  43. #define IPOPT_MEASUREMENT 0x40
  44. #define IPOPT_RESERVED2 0x60
  45. #define IPOPT_END (0 | IPOPT_CONTROL)
  46. #define IPOPT_NOOP (1 | IPOPT_CONTROL)
  47. #define IPOPT_SEC (2 | IPOPT_CONTROL | IPOPT_COPY)
  48. #define IPOPT_LSRR (3 | IPOPT_CONTROL | IPOPT_COPY)
  49. #define IPOPT_TIMESTAMP (4 | IPOPT_MEASUREMENT)
  50. #define IPOPT_RR (7 | IPOPT_CONTROL)
  51. #define IPOPT_SID (8 | IPOPT_CONTROL | IPOPT_COPY)
  52. #define IPOPT_SSRR (9 | IPOPT_CONTROL | IPOPT_COPY)
  53. #define IPOPT_RA (20 | IPOPT_CONTROL | IPOPT_COPY)
  54. #define IPVERSION 4
  55. #define MAXTTL 255
  56. #define IPDEFTTL 64
  57. /* struct timestamp, struct route and MAX_ROUTES are removed.
  58. REASONS: it is clear that nobody used them because:
  59. - MAX_ROUTES value was wrong.
  60. - "struct route" was wrong.
  61. - "struct timestamp" had fatally misaligned bitfields and was completely unusable.
  62. */
  63. #define IPOPT_OPTVAL 0
  64. #define IPOPT_OLEN 1
  65. #define IPOPT_OFFSET 2
  66. #define IPOPT_MINOFF 4
  67. #define MAX_IPOPTLEN 40
  68. #define IPOPT_NOP IPOPT_NOOP
  69. #define IPOPT_EOL IPOPT_END
  70. #define IPOPT_TS IPOPT_TIMESTAMP
  71. #define IPOPT_TS_TSONLY 0 /* timestamps only */
  72. #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
  73. #define IPOPT_TS_PRESPEC 3 /* specified modules only */
  74. #ifdef PLATFORM_LINUX
  75. struct ip_options {
  76. __u32 faddr; /* Saved first hop address */
  77. unsigned char optlen;
  78. unsigned char srr;
  79. unsigned char rr;
  80. unsigned char ts;
  81. unsigned char is_setbyuser:1, /* Set by setsockopt? */
  82. is_data:1, /* Options in __data, rather than skb */
  83. is_strictroute:1, /* Strict source route */
  84. srr_is_hit:1, /* Packet destination addr was our one */
  85. is_changed:1, /* IP checksum more not valid */
  86. rr_needaddr:1, /* Need to record addr of outgoing dev */
  87. ts_needtime:1, /* Need to record timestamp */
  88. ts_needaddr:1; /* Need to record addr of outgoing dev */
  89. unsigned char router_alert;
  90. unsigned char __pad1;
  91. unsigned char __pad2;
  92. unsigned char __data[0];
  93. };
  94. #define optlength(opt) (sizeof(struct ip_options) + opt->optlen)
  95. #endif
  96. struct iphdr {
  97. #if defined(__LITTLE_ENDIAN_BITFIELD)
  98. __u8 ihl:4,
  99. version:4;
  100. #elif defined (__BIG_ENDIAN_BITFIELD)
  101. __u8 version:4,
  102. ihl:4;
  103. #else
  104. #error "Please fix <asm/byteorder.h>"
  105. #endif
  106. __u8 tos;
  107. __u16 tot_len;
  108. __u16 id;
  109. __u16 frag_off;
  110. __u8 ttl;
  111. __u8 protocol;
  112. __u16 check;
  113. __u32 saddr;
  114. __u32 daddr;
  115. /*The options start here. */
  116. };
  117. #endif /* _LINUX_IP_H */