Commit 0928a95ffe91862938cee997c9e30602fa7884ab
Committed by
Anthony Liguori
1 parent
f8d926e9
slirp: Reassign same address to same DHCP client
In case a client restarts a DHCP recovery without releasing its old address, reassign the same address to prevent consuming free addresses and moving away from the standard client address. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Showing
1 changed file
with
5 additions
and
3 deletions
slirp/bootp.c
@@ -49,13 +49,15 @@ if (slirp_debug & DBG_CALL) { fprintf(dfd, fmt, ## __VA_ARGS__); fflush(dfd); } | @@ -49,13 +49,15 @@ if (slirp_debug & DBG_CALL) { fprintf(dfd, fmt, ## __VA_ARGS__); fflush(dfd); } | ||
49 | #define dprintf(fmt, ...) | 49 | #define dprintf(fmt, ...) |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | -static BOOTPClient *get_new_addr(struct in_addr *paddr) | 52 | +static BOOTPClient *get_new_addr(struct in_addr *paddr, |
53 | + const uint8_t *macaddr) | ||
53 | { | 54 | { |
54 | BOOTPClient *bc; | 55 | BOOTPClient *bc; |
55 | int i; | 56 | int i; |
56 | 57 | ||
57 | for(i = 0; i < NB_ADDR; i++) { | 58 | for(i = 0; i < NB_ADDR; i++) { |
58 | - if (!bootp_clients[i].allocated) | 59 | + bc = &bootp_clients[i]; |
60 | + if (!bc->allocated || !memcmp(macaddr, bc->macaddr, 6)) | ||
59 | goto found; | 61 | goto found; |
60 | } | 62 | } |
61 | return NULL; | 63 | return NULL; |
@@ -192,7 +194,7 @@ static void bootp_reply(const struct bootp_t *bp) | @@ -192,7 +194,7 @@ static void bootp_reply(const struct bootp_t *bp) | ||
192 | } | 194 | } |
193 | if (!bc) { | 195 | if (!bc) { |
194 | new_addr: | 196 | new_addr: |
195 | - bc = get_new_addr(&daddr.sin_addr); | 197 | + bc = get_new_addr(&daddr.sin_addr, client_ethaddr); |
196 | if (!bc) { | 198 | if (!bc) { |
197 | dprintf("no address left\n"); | 199 | dprintf("no address left\n"); |
198 | return; | 200 | return; |