uint32_t ipv6_address_find_best_match(iot_interface_t ** pp_interface, ipv6_addr_t * p_addr_r, const ipv6_addr_t * p_addr_f) { VERIFY_MODULE_IS_INITIALIZED(); NULL_PARAM_CHECK(p_addr_f); NULL_PARAM_CHECK(pp_interface); uint32_t index; uint32_t err_code; uint32_t addr_index; uint32_t match_temp = 0; uint32_t match_best = 0; ipv6_addr_t * p_best_addr = NULL; IPV6_MUTEX_LOCK(); err_code = interface_find(pp_interface, p_addr_f); if (err_code == NRF_SUCCESS && p_addr_r) { uint32_t interface_id = (uint32_t)(*pp_interface)->p_upper_stack; for (index = 0; index < IPV6_MAX_ADDRESS_PER_INTERFACE; index++) { addr_index = m_interfaces[interface_id].addr_range[index]; if (addr_index != IPV6_INVALID_ADDR_INDEX) { if (m_address_table[addr_index].state == IPV6_ADDR_STATE_PREFERRED) { match_temp = addr_bit_equal(p_addr_f, &m_address_table[addr_index].addr); if (match_temp >= match_best) { match_best = match_temp; p_best_addr = &m_address_table[addr_index].addr; } } } } // No address found. if (p_best_addr == NULL) { // Set undefined :: address. IPV6_ADDRESS_INITIALIZE(p_addr_r); } else { memcpy(p_addr_r->u8, p_best_addr->u8, IPV6_ADDR_SIZE); } } IPV6_MUTEX_UNLOCK(); return err_code; }
/* 添加桥 */ AP_DECLARE(int) ap_bridge_port_alloc() { bridge_port_t *bridge_port; int rv; if (ap_work_mode != WORK_BRIDGE && ap_work_mode != WORK_ROUTE) { return OK; } bridge_port = NULL; if (ap_bridge_ports) { bridge_port = ap_bridge_ports->next; } while (bridge_port) { if (ap_work_mode == WORK_BRIDGE) { /* 检测桥设备 */ rv = interface_find(bridge_port->br_name); if (rv != OK) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "bridge %s do not exist!\n", bridge_port->br_name); return DECLINED; } /* 调用ebtables设置脚本 */ if (!bridge_port->deploied && !bridge_port->deleted) { rv = create_ebtables_configure(bridge_port->br_name, bridge_port->ser_port, bridge_port->tproxy_port); if (rv != 0) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "create ebtables fail!"); (void)destroy_ebtables_configure(bridge_port->br_name, bridge_port->ser_port, bridge_port->tproxy_port); return DECLINED; } bridge_port->deploied = 1; } } else { /* 调用iptables设置脚本 */ if (!bridge_port->deploied && !bridge_port->deleted) { rv = create_iptables_configure(bridge_port->ser_port, bridge_port->tproxy_port); if (rv != 0) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "create iptables fail!\n"); (void)destroy_iptables_configure(bridge_port->ser_port, bridge_port->tproxy_port); return DECLINED; } bridge_port->deploied = 1; } } bridge_port = bridge_port->next; } return OK; }
static bool interface_handler(const char *ifname, const struct sa *addr, void *arg) { struct agent *ag = arg; int err = 0; /* Skip loopback and link-local addresses */ if (ag->cli->param.skip_local) { if (sa_is_loopback(addr) || sa_is_linklocal(addr)) return false; } if (str_isset(ag->cli->param.ifname) && str_casecmp(ag->cli->param.ifname, ifname)) { return false; } switch (sa_af(addr)) { case AF_INET: if (!ag->cli->param.use_ipv4) return false; break; case AF_INET6: if (!ag->cli->param.use_ipv6) return false; break; } /* NOTE: on some machines an interface is listed twice. */ if (interface_find(ag, addr)) { re_printf("ignoring duplicated interface (%s %j)\n", ifname, addr); return false; } ag->interfacev[ag->interfacec++] = *addr; re_printf("interface: %s %j\n", ifname, addr); if (ag->cli->param.use_udp) err |= add_candidate(ag, addr, IPPROTO_UDP, 0, ifname); if (ag->cli->param.use_tcp) { err |= add_candidate(ag, addr, IPPROTO_TCP, ICE_TCP_SO, ifname); err |= add_candidate(ag, addr, IPPROTO_TCP, ag->client ? ICE_TCP_ACTIVE : ICE_TCP_PASSIVE, ifname); } return err != 0; }
/*---------------------------------------------------------------------*/ int32_t netmap_link_iface(void *ctxt, const unsigned char *iface, const uint16_t batchsize, int8_t qid) { TRACE_NETMAP_FUNC_START(); char nifname[MAX_IFNAMELEN]; netmap_module_context *nmc = (netmap_module_context *)ctxt; netmap_iface_context *nic = NULL; /* setting nm-ifname*/ sprintf(nifname, "netmap:%s", iface); /* check if the interface has been registered with some other engine */ netiface *nif = interface_find((char *)iface); if (nif == NULL) { nic = calloc(1, sizeof(netmap_iface_context)); if (nic == NULL) { TRACE_ERR("Can't allocate memory for " "netmap_iface_context (for %s)\n", iface); TRACE_NETMAP_FUNC_END(); return -1; } /* resetting base_nmd */ memset(&nic->base_nmd, 0, sizeof(struct nm_desc)); /* resetting fd to -1 */ nic->global_fd = nmc->local_fd = -1; /* use some extra rings */ nic->base_nmd.req.nr_arg3 = NM_EXTRA_BUFS; nic->nmd_flags |= NM_OPEN_ARG3; nic->global_nmd = nm_open((char *)nifname, NULL, nic->nmd_flags, &nic->base_nmd); if (nic->global_nmd == NULL) { TRACE_LOG("Unable to open %s: %s\n", iface, strerror(errno)); free(nic); TRACE_NETMAP_FUNC_END(); return -1; } nic->global_fd = nic->global_nmd->fd; TRACE_DEBUG_LOG("mapped %dKB at %p\n", nic->global_nmd->req.nr_memsize>>10, nic->global_nmd->mem); TRACE_DEBUG_LOG("zerocopy %s", (nic->global_nmd->mem == nic->base_nmd.mem) ? "enabled\n" : "disabled\n"); if (qid != -1) { nic->global_nmd->req.nr_flags = NR_REG_ONE_NIC; nic->global_nmd->req.nr_ringid = qid; } /* create interface entry */ create_interface_entry(iface, (qid == -1) ? NO_QUEUES : HW_QUEUES, IO_NETMAP, nic, nmc->eng); } else { /* otherwise check if that interface can be registered */