Free (GPLv2) TCP/IP stack developed by TASS Belgium
Fork of PicoTCP by
modules/pico_ipv4.h@6:55b47464d5bc, 2013-05-31 (annotated)
- Committer:
- tass
- Date:
- Fri May 31 11:34:20 2013 +0000
- Revision:
- 6:55b47464d5bc
Integrated mbed friendly sockets;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tass | 6:55b47464d5bc | 1 | /********************************************************************* |
tass | 6:55b47464d5bc | 2 | PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved. |
tass | 6:55b47464d5bc | 3 | See LICENSE and COPYING for usage. |
tass | 6:55b47464d5bc | 4 | |
tass | 6:55b47464d5bc | 5 | . |
tass | 6:55b47464d5bc | 6 | |
tass | 6:55b47464d5bc | 7 | *********************************************************************/ |
tass | 6:55b47464d5bc | 8 | #ifndef _INCLUDE_PICO_IPV4 |
tass | 6:55b47464d5bc | 9 | #define _INCLUDE_PICO_IPV4 |
tass | 6:55b47464d5bc | 10 | #include "pico_addressing.h" |
tass | 6:55b47464d5bc | 11 | #include "pico_protocol.h" |
tass | 6:55b47464d5bc | 12 | #include "pico_tree.h" |
tass | 6:55b47464d5bc | 13 | |
tass | 6:55b47464d5bc | 14 | #define PICO_IPV4_INADDR_ANY 0x00000000U |
tass | 6:55b47464d5bc | 15 | |
tass | 6:55b47464d5bc | 16 | #define PICO_SIZE_IP4HDR ((sizeof(struct pico_ipv4_hdr))) |
tass | 6:55b47464d5bc | 17 | #define PICO_IPV4_DONTFRAG 0x4000 |
tass | 6:55b47464d5bc | 18 | #define PICO_IPV4_MOREFRAG 0x2000 |
tass | 6:55b47464d5bc | 19 | #define PICO_IPV4_FRAG_MASK 0x1FFF |
tass | 6:55b47464d5bc | 20 | #define PICO_IPV4_DEFAULT_TTL 64 |
tass | 6:55b47464d5bc | 21 | |
tass | 6:55b47464d5bc | 22 | extern struct pico_protocol pico_proto_ipv4; |
tass | 6:55b47464d5bc | 23 | |
tass | 6:55b47464d5bc | 24 | struct __attribute__((packed)) pico_ipv4_hdr { |
tass | 6:55b47464d5bc | 25 | uint8_t vhl; |
tass | 6:55b47464d5bc | 26 | uint8_t tos; |
tass | 6:55b47464d5bc | 27 | uint16_t len; |
tass | 6:55b47464d5bc | 28 | uint16_t id; |
tass | 6:55b47464d5bc | 29 | uint16_t frag; |
tass | 6:55b47464d5bc | 30 | uint8_t ttl; |
tass | 6:55b47464d5bc | 31 | uint8_t proto; |
tass | 6:55b47464d5bc | 32 | uint16_t crc; |
tass | 6:55b47464d5bc | 33 | struct pico_ip4 src; |
tass | 6:55b47464d5bc | 34 | struct pico_ip4 dst; |
tass | 6:55b47464d5bc | 35 | uint8_t options[0]; |
tass | 6:55b47464d5bc | 36 | }; |
tass | 6:55b47464d5bc | 37 | |
tass | 6:55b47464d5bc | 38 | struct __attribute__((packed)) pico_ipv4_pseudo_hdr |
tass | 6:55b47464d5bc | 39 | { |
tass | 6:55b47464d5bc | 40 | struct pico_ip4 src; |
tass | 6:55b47464d5bc | 41 | struct pico_ip4 dst; |
tass | 6:55b47464d5bc | 42 | uint8_t zeros; |
tass | 6:55b47464d5bc | 43 | uint8_t proto; |
tass | 6:55b47464d5bc | 44 | uint16_t len; |
tass | 6:55b47464d5bc | 45 | }; |
tass | 6:55b47464d5bc | 46 | |
tass | 6:55b47464d5bc | 47 | /* Interface: link to device */ |
tass | 6:55b47464d5bc | 48 | struct pico_mcast_list; |
tass | 6:55b47464d5bc | 49 | |
tass | 6:55b47464d5bc | 50 | struct pico_ipv4_link |
tass | 6:55b47464d5bc | 51 | { |
tass | 6:55b47464d5bc | 52 | struct pico_device *dev; |
tass | 6:55b47464d5bc | 53 | struct pico_ip4 address; |
tass | 6:55b47464d5bc | 54 | struct pico_ip4 netmask; |
tass | 6:55b47464d5bc | 55 | #ifdef PICO_SUPPORT_MCAST |
tass | 6:55b47464d5bc | 56 | struct pico_tree *MCASTGroups; |
tass | 6:55b47464d5bc | 57 | uint8_t mcast_compatibility; |
tass | 6:55b47464d5bc | 58 | uint8_t mcast_last_query_interval; |
tass | 6:55b47464d5bc | 59 | #endif |
tass | 6:55b47464d5bc | 60 | }; |
tass | 6:55b47464d5bc | 61 | |
tass | 6:55b47464d5bc | 62 | #ifdef PICO_SUPPORT_MCAST |
tass | 6:55b47464d5bc | 63 | struct pico_mcast_group { |
tass | 6:55b47464d5bc | 64 | uint8_t filter_mode; |
tass | 6:55b47464d5bc | 65 | uint16_t reference_count; |
tass | 6:55b47464d5bc | 66 | struct pico_ip4 mcast_addr; |
tass | 6:55b47464d5bc | 67 | struct pico_tree MCASTSources; |
tass | 6:55b47464d5bc | 68 | }; |
tass | 6:55b47464d5bc | 69 | #endif |
tass | 6:55b47464d5bc | 70 | |
tass | 6:55b47464d5bc | 71 | int pico_ipv4_to_string(char *ipbuf, const uint32_t ip); |
tass | 6:55b47464d5bc | 72 | int pico_string_to_ipv4(const char *ipstr, uint32_t *ip); |
tass | 6:55b47464d5bc | 73 | int pico_ipv4_valid_netmask(uint32_t mask); |
tass | 6:55b47464d5bc | 74 | int pico_ipv4_is_unicast(uint32_t address); |
tass | 6:55b47464d5bc | 75 | int pico_ipv4_is_multicast(uint32_t address); |
tass | 6:55b47464d5bc | 76 | int pico_ipv4_is_broadcast(uint32_t addr); |
tass | 6:55b47464d5bc | 77 | |
tass | 6:55b47464d5bc | 78 | int pico_ipv4_link_add(struct pico_device *dev, struct pico_ip4 address, struct pico_ip4 netmask); |
tass | 6:55b47464d5bc | 79 | int pico_ipv4_link_del(struct pico_device *dev, struct pico_ip4 address); |
tass | 6:55b47464d5bc | 80 | int pico_ipv4_rebound(struct pico_frame *f); |
tass | 6:55b47464d5bc | 81 | |
tass | 6:55b47464d5bc | 82 | int pico_ipv4_frame_push(struct pico_frame *f, struct pico_ip4 *dst, uint8_t proto); |
tass | 6:55b47464d5bc | 83 | struct pico_ipv4_link *pico_ipv4_link_get(struct pico_ip4 *address); |
tass | 6:55b47464d5bc | 84 | struct pico_ipv4_link *pico_ipv4_link_by_dev(struct pico_device *dev); |
tass | 6:55b47464d5bc | 85 | struct pico_device *pico_ipv4_link_find(struct pico_ip4 *address); |
tass | 6:55b47464d5bc | 86 | struct pico_ip4 *pico_ipv4_source_find(struct pico_ip4 *dst); |
tass | 6:55b47464d5bc | 87 | int pico_ipv4_route_add(struct pico_ip4 address, struct pico_ip4 netmask, struct pico_ip4 gateway, int metric, struct pico_ipv4_link *link); |
tass | 6:55b47464d5bc | 88 | int pico_ipv4_route_del(struct pico_ip4 address, struct pico_ip4 netmask, struct pico_ip4 gateway, int metric, struct pico_ipv4_link *link); |
tass | 6:55b47464d5bc | 89 | struct pico_ip4 pico_ipv4_route_get_gateway(struct pico_ip4 *addr); |
tass | 6:55b47464d5bc | 90 | void pico_ipv4_unreachable(struct pico_frame *f, int err); |
tass | 6:55b47464d5bc | 91 | |
tass | 6:55b47464d5bc | 92 | int pico_ipv4_mcast_join(struct pico_ip4 *mcast_link, struct pico_ip4 *mcast_group, uint8_t reference_count, uint8_t filter_mode, struct pico_tree *MCASTFilter); |
tass | 6:55b47464d5bc | 93 | int pico_ipv4_mcast_leave(struct pico_ip4 *mcast_link, struct pico_ip4 *mcast_group, uint8_t reference_count, uint8_t filter_mode, struct pico_tree *MCASTFilter); |
tass | 6:55b47464d5bc | 94 | struct pico_ipv4_link *pico_ipv4_get_default_mcastlink(void); |
tass | 6:55b47464d5bc | 95 | |
tass | 6:55b47464d5bc | 96 | #endif /* _INCLUDE_PICO_IPV4 */ |