3 * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
8 void ndp_table_add(Slirp
*slirp
, struct in6_addr ip_addr
,
9 uint8_t ethaddr
[ETH_ALEN
])
11 char addrstr
[INET6_ADDRSTRLEN
];
12 NdpTable
*ndp_table
= &slirp
->ndp_table
;
15 inet_ntop(AF_INET6
, &(ip_addr
), addrstr
, INET6_ADDRSTRLEN
);
17 DEBUG_CALL("ndp_table_add");
18 DEBUG_ARG("ip = %s", addrstr
);
19 DEBUG_ARG("hw addr = %02x:%02x:%02x:%02x:%02x:%02x",
20 ethaddr
[0], ethaddr
[1], ethaddr
[2],
21 ethaddr
[3], ethaddr
[4], ethaddr
[5]);
23 if (IN6_IS_ADDR_MULTICAST(&ip_addr
) || in6_zero(&ip_addr
)) {
24 /* Do not register multicast or unspecified addresses */
25 DEBUG_CALL(" abort: do not register multicast or unspecified address");
29 /* Search for an entry */
30 for (i
= 0; i
< NDP_TABLE_SIZE
; i
++) {
31 if (in6_equal(&ndp_table
->table
[i
].ip_addr
, &ip_addr
)) {
32 DEBUG_CALL(" already in table: update the entry");
33 /* Update the entry */
34 memcpy(ndp_table
->table
[i
].eth_addr
, ethaddr
, ETH_ALEN
);
39 /* No entry found, create a new one */
40 DEBUG_CALL(" create new entry");
41 ndp_table
->table
[ndp_table
->next_victim
].ip_addr
= ip_addr
;
42 memcpy(ndp_table
->table
[ndp_table
->next_victim
].eth_addr
,
44 ndp_table
->next_victim
= (ndp_table
->next_victim
+ 1) % NDP_TABLE_SIZE
;
47 bool ndp_table_search(Slirp
*slirp
, struct in6_addr ip_addr
,
48 uint8_t out_ethaddr
[ETH_ALEN
])
50 char addrstr
[INET6_ADDRSTRLEN
];
51 NdpTable
*ndp_table
= &slirp
->ndp_table
;
54 inet_ntop(AF_INET6
, &(ip_addr
), addrstr
, INET6_ADDRSTRLEN
);
56 DEBUG_CALL("ndp_table_search");
57 DEBUG_ARG("ip = %s", addrstr
);
59 assert(!in6_zero(&ip_addr
));
61 /* Multicast address: fec0::abcd:efgh/8 -> 33:33:ab:cd:ef:gh */
62 if (IN6_IS_ADDR_MULTICAST(&ip_addr
)) {
63 out_ethaddr
[0] = 0x33; out_ethaddr
[1] = 0x33;
64 out_ethaddr
[2] = ip_addr
.s6_addr
[12];
65 out_ethaddr
[3] = ip_addr
.s6_addr
[13];
66 out_ethaddr
[4] = ip_addr
.s6_addr
[14];
67 out_ethaddr
[5] = ip_addr
.s6_addr
[15];
68 DEBUG_ARG("multicast addr = %02x:%02x:%02x:%02x:%02x:%02x",
69 out_ethaddr
[0], out_ethaddr
[1], out_ethaddr
[2],
70 out_ethaddr
[3], out_ethaddr
[4], out_ethaddr
[5]);
74 for (i
= 0; i
< NDP_TABLE_SIZE
; i
++) {
75 if (in6_equal(&ndp_table
->table
[i
].ip_addr
, &ip_addr
)) {
76 memcpy(out_ethaddr
, ndp_table
->table
[i
].eth_addr
, ETH_ALEN
);
77 DEBUG_ARG("found hw addr = %02x:%02x:%02x:%02x:%02x:%02x",
78 out_ethaddr
[0], out_ethaddr
[1], out_ethaddr
[2],
79 out_ethaddr
[3], out_ethaddr
[4], out_ethaddr
[5]);
84 DEBUG_CALL(" ip not found in table");