1 | /**
|
---|
2 | * @file
|
---|
3 | *
|
---|
4 | * AutoIP Automatic LinkLocal IP Configuration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | *
|
---|
9 | * Copyright (c) 2007 Dominik Spies <kontakt@dspies.de>
|
---|
10 | * All rights reserved.
|
---|
11 | *
|
---|
12 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
13 | * are permitted provided that the following conditions are met:
|
---|
14 | *
|
---|
15 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
16 | * this list of conditions and the following disclaimer.
|
---|
17 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
18 | * this list of conditions and the following disclaimer in the documentation
|
---|
19 | * and/or other materials provided with the distribution.
|
---|
20 | * 3. The name of the author may not be used to endorse or promote products
|
---|
21 | * derived from this software without specific prior written permission.
|
---|
22 | *
|
---|
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
---|
24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
---|
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
---|
26 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
---|
28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
---|
31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
---|
32 | * OF SUCH DAMAGE.
|
---|
33 | *
|
---|
34 | * Author: Dominik Spies <kontakt@dspies.de>
|
---|
35 | *
|
---|
36 | * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform
|
---|
37 | * with RFC 3927.
|
---|
38 | *
|
---|
39 | *
|
---|
40 | * Please coordinate changes and requests with Dominik Spies
|
---|
41 | * <kontakt@dspies.de>
|
---|
42 | */
|
---|
43 |
|
---|
44 | #ifndef __LWIP_AUTOIP_H__
|
---|
45 | #define __LWIP_AUTOIP_H__
|
---|
46 |
|
---|
47 | #include "lwip/opt.h"
|
---|
48 |
|
---|
49 | #if LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */
|
---|
50 |
|
---|
51 | #include "lwip/netif.h"
|
---|
52 | #include "lwip/udp.h"
|
---|
53 | #include "netif/etharp.h"
|
---|
54 |
|
---|
55 | #ifdef __cplusplus
|
---|
56 | extern "C" {
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | /* AutoIP Timing */
|
---|
60 | #define AUTOIP_TMR_INTERVAL 100
|
---|
61 | #define AUTOIP_TICKS_PER_SECOND (1000 / AUTOIP_TMR_INTERVAL)
|
---|
62 |
|
---|
63 | /* RFC 3927 Constants */
|
---|
64 | #define PROBE_WAIT 1 /* second (initial random delay) */
|
---|
65 | #define PROBE_MIN 1 /* second (minimum delay till repeated probe) */
|
---|
66 | #define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */
|
---|
67 | #define PROBE_NUM 3 /* (number of probe packets) */
|
---|
68 | #define ANNOUNCE_NUM 2 /* (number of announcement packets) */
|
---|
69 | #define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */
|
---|
70 | #define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */
|
---|
71 | #define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */
|
---|
72 | #define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */
|
---|
73 | #define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */
|
---|
74 |
|
---|
75 | /* AutoIP client states */
|
---|
76 | #define AUTOIP_STATE_OFF 0
|
---|
77 | #define AUTOIP_STATE_PROBING 1
|
---|
78 | #define AUTOIP_STATE_ANNOUNCING 2
|
---|
79 | #define AUTOIP_STATE_BOUND 3
|
---|
80 |
|
---|
81 | struct autoip
|
---|
82 | {
|
---|
83 | ip_addr_t llipaddr; /* the currently selected, probed, announced or used LL IP-Address */
|
---|
84 | u8_t state; /* current AutoIP state machine state */
|
---|
85 | u8_t sent_num; /* sent number of probes or announces, dependent on state */
|
---|
86 | u16_t ttw; /* ticks to wait, tick is AUTOIP_TMR_INTERVAL long */
|
---|
87 | u8_t lastconflict; /* ticks until a conflict can be solved by defending */
|
---|
88 | u8_t tried_llipaddr; /* total number of probed/used Link Local IP-Addresses */
|
---|
89 | };
|
---|
90 |
|
---|
91 |
|
---|
92 | #define autoip_init() /* Compatibility define, no init needed. */
|
---|
93 |
|
---|
94 | /** Set a struct autoip allocated by the application to work with */
|
---|
95 | void autoip_set_struct(struct netif *netif, struct autoip *autoip);
|
---|
96 |
|
---|
97 | /** Start AutoIP client */
|
---|
98 | err_t autoip_start(struct netif *netif);
|
---|
99 |
|
---|
100 | /** Stop AutoIP client */
|
---|
101 | err_t autoip_stop(struct netif *netif);
|
---|
102 |
|
---|
103 | /** Handles every incoming ARP Packet, called by etharp_arp_input */
|
---|
104 | void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr);
|
---|
105 |
|
---|
106 | /** Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds */
|
---|
107 | void autoip_tmr(void);
|
---|
108 |
|
---|
109 | /** Handle a possible change in the network configuration */
|
---|
110 | void autoip_network_changed(struct netif *netif);
|
---|
111 |
|
---|
112 | #ifdef __cplusplus
|
---|
113 | }
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | #endif /* LWIP_AUTOIP */
|
---|
117 |
|
---|
118 | #endif /* __LWIP_AUTOIP_H__ */
|
---|