| 1 |
606 |
jeremybenn |
/*
|
| 2 |
|
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
| 3 |
|
|
* All rights reserved.
|
| 4 |
|
|
*
|
| 5 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
| 6 |
|
|
* are permitted provided that the following conditions are met:
|
| 7 |
|
|
*
|
| 8 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
| 9 |
|
|
* this list of conditions and the following disclaimer.
|
| 10 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 11 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
| 12 |
|
|
* and/or other materials provided with the distribution.
|
| 13 |
|
|
* 3. The name of the author may not be used to endorse or promote products
|
| 14 |
|
|
* derived from this software without specific prior written permission.
|
| 15 |
|
|
*
|
| 16 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
| 17 |
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
| 18 |
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
| 19 |
|
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
| 20 |
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
| 21 |
|
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 22 |
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 23 |
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
| 24 |
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
| 25 |
|
|
* OF SUCH DAMAGE.
|
| 26 |
|
|
*
|
| 27 |
|
|
* This file is part of the lwIP TCP/IP stack.
|
| 28 |
|
|
*
|
| 29 |
|
|
* Author: Adam Dunkels <adam@sics.se>
|
| 30 |
|
|
*
|
| 31 |
|
|
*/
|
| 32 |
|
|
#ifndef __LWIP_IP_H__
|
| 33 |
|
|
#define __LWIP_IP_H__
|
| 34 |
|
|
|
| 35 |
|
|
#include "lwip/opt.h"
|
| 36 |
|
|
|
| 37 |
|
|
#include "lwip/def.h"
|
| 38 |
|
|
#include "lwip/pbuf.h"
|
| 39 |
|
|
#include "lwip/ip_addr.h"
|
| 40 |
|
|
#include "lwip/err.h"
|
| 41 |
|
|
|
| 42 |
|
|
#ifdef __cplusplus
|
| 43 |
|
|
extern "C" {
|
| 44 |
|
|
#endif
|
| 45 |
|
|
|
| 46 |
|
|
#define ip_init() /* Compatibility define, not init needed. */
|
| 47 |
|
|
struct netif *ip_route(struct ip_addr *dest);
|
| 48 |
|
|
err_t ip_input(struct pbuf *p, struct netif *inp);
|
| 49 |
|
|
err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
| 50 |
|
|
u8_t ttl, u8_t tos, u8_t proto);
|
| 51 |
|
|
err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
| 52 |
|
|
u8_t ttl, u8_t tos, u8_t proto,
|
| 53 |
|
|
struct netif *netif);
|
| 54 |
|
|
|
| 55 |
|
|
#define IP_HLEN 20
|
| 56 |
|
|
|
| 57 |
|
|
#define IP_PROTO_ICMP 1
|
| 58 |
|
|
#define IP_PROTO_UDP 17
|
| 59 |
|
|
#define IP_PROTO_UDPLITE 136
|
| 60 |
|
|
#define IP_PROTO_TCP 6
|
| 61 |
|
|
|
| 62 |
|
|
/* This is passed as the destination address to ip_output_if (not
|
| 63 |
|
|
to ip_output), meaning that an IP header already is constructed
|
| 64 |
|
|
in the pbuf. This is used when TCP retransmits. */
|
| 65 |
|
|
#ifdef IP_HDRINCL
|
| 66 |
|
|
#undef IP_HDRINCL
|
| 67 |
|
|
#endif /* IP_HDRINCL */
|
| 68 |
|
|
#define IP_HDRINCL NULL
|
| 69 |
|
|
|
| 70 |
|
|
#if LWIP_NETIF_HWADDRHINT
|
| 71 |
|
|
#define IP_PCB_ADDRHINT ;u8_t addr_hint
|
| 72 |
|
|
#else
|
| 73 |
|
|
#define IP_PCB_ADDRHINT
|
| 74 |
|
|
#endif /* LWIP_NETIF_HWADDRHINT */
|
| 75 |
|
|
|
| 76 |
|
|
/* This is the common part of all PCB types. It needs to be at the
|
| 77 |
|
|
beginning of a PCB type definition. It is located here so that
|
| 78 |
|
|
changes to this common part are made in one location instead of
|
| 79 |
|
|
having to change all PCB structs. */
|
| 80 |
|
|
#define IP_PCB \
|
| 81 |
|
|
/* ip addresses in network byte order */ \
|
| 82 |
|
|
struct ip_addr local_ip; \
|
| 83 |
|
|
struct ip_addr remote_ip; \
|
| 84 |
|
|
/* Socket options */ \
|
| 85 |
|
|
u16_t so_options; \
|
| 86 |
|
|
/* Type Of Service */ \
|
| 87 |
|
|
u8_t tos; \
|
| 88 |
|
|
/* Time To Live */ \
|
| 89 |
|
|
u8_t ttl \
|
| 90 |
|
|
/* link layer address resolution hint */ \
|
| 91 |
|
|
IP_PCB_ADDRHINT
|
| 92 |
|
|
|
| 93 |
|
|
struct ip_pcb {
|
| 94 |
|
|
/* Common members of all PCB types */
|
| 95 |
|
|
IP_PCB;
|
| 96 |
|
|
};
|
| 97 |
|
|
|
| 98 |
|
|
/*
|
| 99 |
|
|
* Option flags per-socket. These are the same like SO_XXX.
|
| 100 |
|
|
*/
|
| 101 |
|
|
#define SOF_DEBUG (u16_t)0x0001U /* turn on debugging info recording */
|
| 102 |
|
|
#define SOF_ACCEPTCONN (u16_t)0x0002U /* socket has had listen() */
|
| 103 |
|
|
#define SOF_REUSEADDR (u16_t)0x0004U /* allow local address reuse */
|
| 104 |
|
|
#define SOF_KEEPALIVE (u16_t)0x0008U /* keep connections alive */
|
| 105 |
|
|
#define SOF_DONTROUTE (u16_t)0x0010U /* just use interface addresses */
|
| 106 |
|
|
#define SOF_BROADCAST (u16_t)0x0020U /* permit sending of broadcast msgs */
|
| 107 |
|
|
#define SOF_USELOOPBACK (u16_t)0x0040U /* bypass hardware when possible */
|
| 108 |
|
|
#define SOF_LINGER (u16_t)0x0080U /* linger on close if data present */
|
| 109 |
|
|
#define SOF_OOBINLINE (u16_t)0x0100U /* leave received OOB data in line */
|
| 110 |
|
|
#define SOF_REUSEPORT (u16_t)0x0200U /* allow local address & port reuse */
|
| 111 |
|
|
|
| 112 |
|
|
|
| 113 |
|
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
| 114 |
|
|
# include "arch/bpstruct.h"
|
| 115 |
|
|
#endif
|
| 116 |
|
|
PACK_STRUCT_BEGIN
|
| 117 |
|
|
#if (defined(__MWERKS__) || defined(__CWCC__))
|
| 118 |
|
|
#pragma options align= packed
|
| 119 |
|
|
#endif
|
| 120 |
|
|
struct ip_hdr {
|
| 121 |
|
|
/* version / header length / type of service */
|
| 122 |
|
|
PACK_STRUCT_FIELD(u16_t _v_hl_tos);
|
| 123 |
|
|
/* total length */
|
| 124 |
|
|
PACK_STRUCT_FIELD(u16_t _len);
|
| 125 |
|
|
/* identification */
|
| 126 |
|
|
PACK_STRUCT_FIELD(u16_t _id);
|
| 127 |
|
|
/* fragment offset field */
|
| 128 |
|
|
PACK_STRUCT_FIELD(u16_t _offset);
|
| 129 |
|
|
#define IP_RF 0x8000 /* reserved fragment flag */
|
| 130 |
|
|
#define IP_DF 0x4000 /* dont fragment flag */
|
| 131 |
|
|
#define IP_MF 0x2000 /* more fragments flag */
|
| 132 |
|
|
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
| 133 |
|
|
/* time to live / protocol*/
|
| 134 |
|
|
PACK_STRUCT_FIELD(u16_t _ttl_proto);
|
| 135 |
|
|
/* checksum */
|
| 136 |
|
|
PACK_STRUCT_FIELD(u16_t _chksum);
|
| 137 |
|
|
/* source and destination IP addresses */
|
| 138 |
|
|
PACK_STRUCT_FIELD(struct ip_addr src);
|
| 139 |
|
|
PACK_STRUCT_FIELD(struct ip_addr dest);
|
| 140 |
|
|
} PACK_STRUCT_STRUCT;
|
| 141 |
|
|
PACK_STRUCT_END
|
| 142 |
|
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
| 143 |
|
|
# include "arch/epstruct.h"
|
| 144 |
|
|
#endif
|
| 145 |
|
|
|
| 146 |
|
|
#define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
|
| 147 |
|
|
#define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
|
| 148 |
|
|
#define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)
|
| 149 |
|
|
#define IPH_LEN(hdr) ((hdr)->_len)
|
| 150 |
|
|
#define IPH_ID(hdr) ((hdr)->_id)
|
| 151 |
|
|
#define IPH_OFFSET(hdr) ((hdr)->_offset)
|
| 152 |
|
|
#define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)
|
| 153 |
|
|
#define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)
|
| 154 |
|
|
#define IPH_CHKSUM(hdr) ((hdr)->_chksum)
|
| 155 |
|
|
|
| 156 |
|
|
#define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
|
| 157 |
|
|
#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
|
| 158 |
|
|
#define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
|
| 159 |
|
|
#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
|
| 160 |
|
|
#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | ((u16_t)(ttl) << 8)))
|
| 161 |
|
|
#define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8)))
|
| 162 |
|
|
#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
|
| 163 |
|
|
|
| 164 |
|
|
#if IP_DEBUG
|
| 165 |
|
|
void ip_debug_print(struct pbuf *p);
|
| 166 |
|
|
#else
|
| 167 |
|
|
#define ip_debug_print(p)
|
| 168 |
|
|
#endif /* IP_DEBUG */
|
| 169 |
|
|
|
| 170 |
|
|
#ifdef __cplusplus
|
| 171 |
|
|
}
|
| 172 |
|
|
#endif
|
| 173 |
|
|
|
| 174 |
|
|
#endif /* __LWIP_IP_H__ */
|
| 175 |
|
|
|
| 176 |
|
|
|