3 * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
6 #include "qemu/osdep.h"
7 #include "qemu-common.h"
10 void ndp_table_add(Slirp
*slirp
, struct in6_addr ip_addr
,
11 uint8_t ethaddr
[ETH_ALEN
])
13 char addrstr
[INET6_ADDRSTRLEN
];
14 NdpTable
*ndp_table
= &slirp
->ndp_table
;
17 inet_ntop(AF_INET6
, &(ip_addr
), addrstr
, INET6_ADDRSTRLEN
);
19 DEBUG_CALL("ndp_table_add");
20 DEBUG_ARG("ip = %s", addrstr
);
21 DEBUG_ARG("hw addr = %02x:%02x:%02x:%02x:%02x:%02x",
22 ethaddr
[0], ethaddr
[1], ethaddr
[2],
23 ethaddr
[3], ethaddr
[4], ethaddr
[5]);
25 if (IN6_IS_ADDR_MULTICAST(&ip_addr
) || in6_zero(&ip_addr
)) {
26 /* Do not register multicast or unspecified addresses */
27 DEBUG_CALL(" abort: do not register multicast or unspecified address");
31 /* Search for an entry */
32 for (i
= 0; i
< NDP_TABLE_SIZE
; i
++) {
33 if (in6_equal(&ndp_table
->table
[i
].ip_addr
, &ip_addr
)) {
34 DEBUG_CALL(" already in table: update the entry");
35 /* Update the entry */
36 memcpy(ndp_table
->table
[i
].eth_addr
, ethaddr
, ETH_ALEN
);
41 /* No entry found, create a new one */
42 DEBUG_CALL(" create new entry");
43 ndp_table
->table
[ndp_table
->next_victim
].ip_addr
= ip_addr
;
44 memcpy(ndp_table
->table
[ndp_table
->next_victim
].eth_addr
,
46 ndp_table
->next_victim
= (ndp_table
->next_victim
+ 1) % NDP_TABLE_SIZE
;
49 bool ndp_table_search(Slirp
*slirp
, struct in6_addr ip_addr
,
50 uint8_t out_ethaddr
[ETH_ALEN
])
52 char addrstr
[INET6_ADDRSTRLEN
];
53 NdpTable
*ndp_table
= &slirp
->ndp_table
;
56 inet_ntop(AF_INET6
, &(ip_addr
), addrstr
, INET6_ADDRSTRLEN
);
58 DEBUG_CALL("ndp_table_search");
59 DEBUG_ARG("ip = %s", addrstr
);
61 assert(!in6_zero(&ip_addr
));
63 /* Multicast address: fec0::abcd:efgh/8 -> 33:33:ab:cd:ef:gh */
64 if (IN6_IS_ADDR_MULTICAST(&ip_addr
)) {
65 out_ethaddr
[0] = 0x33; out_ethaddr
[1] = 0x33;
66 out_ethaddr
[2] = ip_addr
.s6_addr
[12];
67 out_ethaddr
[3] = ip_addr
.s6_addr
[13];
68 out_ethaddr
[4] = ip_addr
.s6_addr
[14];
69 out_ethaddr
[5] = ip_addr
.s6_addr
[15];
70 DEBUG_ARG("multicast addr = %02x:%02x:%02x:%02x:%02x:%02x",
71 out_ethaddr
[0], out_ethaddr
[1], out_ethaddr
[2],
72 out_ethaddr
[3], out_ethaddr
[4], out_ethaddr
[5]);
76 for (i
= 0; i
< NDP_TABLE_SIZE
; i
++) {
77 if (in6_equal(&ndp_table
->table
[i
].ip_addr
, &ip_addr
)) {
78 memcpy(out_ethaddr
, ndp_table
->table
[i
].eth_addr
, ETH_ALEN
);
79 DEBUG_ARG("found hw addr = %02x:%02x:%02x:%02x:%02x:%02x",
80 out_ethaddr
[0], out_ethaddr
[1], out_ethaddr
[2],
81 out_ethaddr
[3], out_ethaddr
[4], out_ethaddr
[5]);
86 DEBUG_CALL(" ip not found in table");