Changeset 83781a22 in mainline for uspace/srv/net


Ignore:
Timestamp:
2013-07-25T13:20:03Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ccdc63e
Parents:
b323a3a
Message:

setup NIC multicast address filter based on the configured IPv6 addresses
(multicast functionality is required for NDP)

Location:
uspace/srv/net
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/ethip/ethip_nic.c

    rb323a3a r83781a22  
    4545#include <device/nic.h>
    4646#include <stdlib.h>
    47 
     47#include <net/socket_codes.h>
     48#include <mem.h>
    4849#include "ethip.h"
    4950#include "ethip_nic.h"
     
    108109{
    109110        ethip_nic_t *nic = calloc(1, sizeof(ethip_nic_t));
    110 
    111111        if (nic == NULL) {
    112112                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating NIC structure. "
     
    114114                return NULL;
    115115        }
    116 
     116       
    117117        link_initialize(&nic->link);
    118118        list_initialize(&nic->addr_list);
    119 
     119       
    120120        return nic;
    121121}
     
    140140        if (nic->svc_name != NULL)
    141141                free(nic->svc_name);
     142       
    142143        free(nic);
    143144}
     
    335336}
    336337
     338/** Setup accepted multicast addresses
     339 *
     340 * Currently the set of accepted multicast addresses is
     341 * determined only based on IPv6 addresses.
     342 *
     343 */
     344static int ethip_nic_setup_multicast(ethip_nic_t *nic)
     345{
     346        log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_setup_multicast()");
     347       
     348        /* Count the number of multicast addresses */
     349       
     350        size_t count = 0;
     351       
     352        list_foreach(nic->addr_list, link) {
     353                ethip_link_addr_t *laddr = list_get_instance(link,
     354                    ethip_link_addr_t, link);
     355               
     356                uint16_t af = inet_addr_get(&laddr->addr, NULL, NULL);
     357                if (af == AF_INET6)
     358                        count++;
     359        }
     360       
     361        if (count == 0)
     362                return nic_multicast_set_mode(nic->sess, NIC_MULTICAST_BLOCKED,
     363                    NULL, 0);
     364       
     365        nic_address_t *mac_list = calloc(count, sizeof(nic_address_t));
     366        if (mac_list == NULL)
     367                return ENOMEM;
     368       
     369        /* Create the multicast MAC list */
     370       
     371        size_t i = 0;
     372       
     373        list_foreach(nic->addr_list, link) {
     374                assert(i < count);
     375               
     376                ethip_link_addr_t *laddr = list_get_instance(link,
     377                    ethip_link_addr_t, link);
     378               
     379                addr128_t v6;
     380                uint16_t af = inet_addr_get(&laddr->addr, NULL, &v6);
     381                if (af != AF_INET6)
     382                        continue;
     383               
     384                addr48_t mac;
     385                addr48_solicited_node(v6, mac);
     386               
     387                /* Avoid duplicate addresses in the list */
     388               
     389                bool found = false;
     390               
     391                for (size_t j = 0; j < i; j++) {
     392                        if (addr48_compare(mac_list[j].address, mac)) {
     393                                found = true;
     394                                break;
     395                        }
     396                }
     397               
     398                if (!found) {
     399                        addr48(mac, mac_list[i].address);
     400                        i++;
     401                } else
     402                        count--;
     403        }
     404       
     405        /* Setup the multicast MAC list */
     406       
     407        int rc = nic_multicast_set_mode(nic->sess, NIC_MULTICAST_LIST,
     408            mac_list, count);
     409       
     410        free(mac_list);
     411        return rc;
     412}
     413
    337414int ethip_nic_addr_add(ethip_nic_t *nic, inet_addr_t *addr)
    338415{
     
    344421       
    345422        list_append(&laddr->link, &nic->addr_list);
    346         return EOK;
     423       
     424        return ethip_nic_setup_multicast(nic);
    347425}
    348426
     
    357435        list_remove(&laddr->link);
    358436        ethip_link_addr_delete(laddr);
    359         return EOK;
     437       
     438        return ethip_nic_setup_multicast(nic);
    360439}
    361440
  • uspace/srv/net/inetsrv/ndp.c

    rb323a3a r83781a22  
    4949#define NDP_REQUEST_TIMEOUT  (3 * 1000 * 1000)
    5050
    51 static addr48_t solicited_node_mac =
    52     {0x33, 0x33, 0xff, 0, 0, 0};
    53 
    5451static addr128_t solicited_node_ip =
    5552    {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0};
    56 
    57 /** Compute solicited node MAC multicast address from target IPv6 address
    58  *
    59  * @param ip_addr  Target IPv6 address
    60  * @param mac_addr Solicited MAC address to be assigned
    61  *
    62  */
    63 static void ndp_solicited_node_mac(addr128_t ip_addr, addr48_t mac_addr)
    64 {
    65         memcpy(mac_addr, solicited_node_mac, 3);
    66         memcpy(mac_addr + 3, ip_addr + 13, 3);
    67 }
    6853
    6954/** Compute solicited node IPv6 multicast address from target IPv6 address
     
    186171        addr128(src_addr, packet.sender_proto_addr);
    187172        addr128(ip_addr, packet.solicited_ip);
    188         ndp_solicited_node_mac(ip_addr, packet.target_hw_addr);
     173        addr48_solicited_node(ip_addr, packet.target_hw_addr);
    189174        ndp_solicited_node_ip(ip_addr, packet.target_proto_addr);
    190175       
Note: See TracChangeset for help on using the changeset viewer.