/* *=========================================================================== * ipnet_sockdev_ioevent *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC int ipnet_sockdev_ioevent(Ipcom_netif *ipcomif, int command, void *data, int fcflags) { int ret = 0; IPCOM_UNUSED_ARG(ipcomif); IPCOM_UNUSED_ARG(data); if (IP_BIT_ISFALSE(fcflags, IP_FLAG_FC_ISRCONTEXT | IP_FLAG_FC_STACKCONTEXT)) IPNET_CODE_LOCK_WRITE(); switch (command) { case IP_EIOXUP: break; case IP_EIOXDOWN: break; default: ret = -1; break; } if (IP_BIT_ISFALSE(fcflags, IP_FLAG_FC_ISRCONTEXT | IP_FLAG_FC_STACKCONTEXT)) IPNET_CODE_UNLOCK(); return ret; }
/* *=========================================================================== * ipnet_usr_sock_tcp_recv *=========================================================================== * Description: Receives data from a TCP stream. * Parameters: sock - The socket to receive data from. * msg - Receive parameters. * flags - IP_MSG_xxx flags. * Returns: 0 = a packet was successfully received, -1 = error. * */ IP_STATIC int ipnet_usr_sock_tcp_recv(Ipnet_socket *sock, struct Ip_msghdr *msg, int flags) { Ip_size_t i; int r; int bytes = 0; /* No support for ancillary data on TCP sockets */ msg->msg_controllen = 0; if (msg->msg_name != IP_NULL) { Ip_socklen_t msg_namelen = msg->msg_namelen; r = ipnet_sys_getname(sock->ipcom.fd, msg->msg_name, &msg_namelen, IP_FALSE); if (r < 0) return r; msg->msg_namelen = msg_namelen; } for (i = 0; i < msg->msg_iovlen; i++) { r = iptcp_usr_recv(sock, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags); if (r == 0) /* EOF received */ break; if (r < 0) { if (bytes > 0) break; IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_WARNING, 1, 1, IPCOM_WV_NETDEVENT_WARNING, IPCOM_WV_NETD_RECV, ipnet_usr_sock_tcp_recv, IPCOM_WV_NETD_BADSOCK, IPCOM_WV_IPNET_SOCK_TCP_MODULE, IPCOM_WV_NETD_TCP4); IPNET_STATS(sock_recvmsg_tcp_err++); return r; } bytes += r; if ((Ip_size_t) r != msg->msg_iov[i].iov_len) /* Continue only if the current buffer was filled to its limit */ break; if (IP_BIT_ISFALSE(flags, IP_MSG_WAITALL)) /* We have some data, return the data we have so far if there isn't anything more to receive */ IP_BIT_SET(flags, IP_MSG_DONTWAIT); } return bytes; }
/* *=========================================================================== * ipnet_udp_fast_deliver_data *=========================================================================== * Description: Deliver an UDP packet to a socket that is bound to a unicast * address. * Parameters: sock - The socket the packet will be delivered to. * pkt - The UDP packet to deliver. * nat_t - NAT_T processing. * Returns: IP_TRUE - The fast path processing was successful. * IP_FALSE - Need to use the normal receive path. * */ IP_STATIC Ip_bool ipnet_udp_fast_deliver_data(Ipnet_socket *sock, Ipcom_pkt *pkt, int *nat_t) { Ipnet_pkt_udp *udp_hdr; int original_start = pkt->start; Ipcom_socket_eventcb event_cb = sock->ipcom.event_cb; udp_hdr = (Ipnet_pkt_udp*) &pkt->data[pkt->tlstart]; if (IP_UNLIKELY(pkt->end - pkt->tlstart < IPNET_UDP_HDR_SIZE || pkt->end - pkt->tlstart < ip_ntohs(udp_hdr->ulen))) return IP_FALSE; if (udp_hdr->sum != 0 && IP_BIT_ISFALSE(pkt->flags, IPCOM_PKT_FLAG_LOOPED_BACK)) { Ip_u16 chksum; /* Only check packets that was not created locally */ #ifdef IPCOM_USE_HW_CHECKSUM_RX if (IP_BIT_ISSET(pkt->flags, IPCOM_PKT_FLAG_HW_CHECKSUM)) chksum = 0; else if (IP_BIT_ISSET(pkt->flags, IPCOM_PKT_FLAG_TL_CHECKSUM)) chksum = ipcom_in_checksum_finish(pkt->chk); else #endif /* IPCOM_USE_HW_CHECKSUM_RX */ { pkt->chk += ipcom_in_checksum_update(&pkt->data[pkt->tlstart], (Ip_size_t) ip_ntohs(udp_hdr->ulen)); chksum = ipcom_in_checksum_finish(pkt->chk); } if (IP_UNLIKELY(chksum != 0)) return IP_FALSE; } pkt->fd = sock->ipcom.fd; pkt->start = pkt->tlstart + IPNET_UDP_HDR_SIZE; if (IP_UNLIKELY(ipnet_udp_encapsulation(sock, pkt, nat_t))) { /* Continue processing */ ipcom_pkt_set_info(pkt, IPNET_PKT_INFO_ENCAP_UDP, sizeof(*udp_hdr), udp_hdr); pkt->start = original_start; return IP_FALSE; } if (ipnet_queue_received_packet(pkt, sock) != 0) { pkt->start = original_start; return IP_FALSE; } if (event_cb != IP_NULL) event_cb(&sock->ipcom, pkt, IP_SOEVENT_CB_INPKT); IPCOM_MIB2(udpInDatagrams++); IPCOM_MIB2_U64_INC(udpHCInDatagrams); return IP_TRUE; }
/* *=========================================================================== * ipnet_rtnetlink_neigh_is *=========================================================================== * Description: * Parameters: * Returns: * */ IP_GLOBAL Ip_bool ipnet_rtnetlink_neigh_is(struct Ipnet_route_entry_struct *rt) { /* Find the first NC entry */ if (IP_BIT_ISSET(rt->hdr.flags, IPNET_RTF_LLINFO) && IP_BIT_ISSET(rt->hdr.flags, IPNET_RTF_HOST) && IP_BIT_ISFALSE(rt->hdr.flags, IPNET_RTF_PROTO2) && rt->gateway && rt->gateway->sa_family == IP_AF_LINK) { /* Found a NC entry */ return IP_TRUE; } return IP_FALSE; }
IP_STATIC Ip_err ipcom_sysvar_setvr(const char *name, const char *value, int flags, int vr) { Ip_err retval; Ipcom_sysvar_tree *tree; if (value == IP_NULL) return IPCOM_SUCCESS; /* simply ignore it silently */ #ifdef IP_PORT_OSE5 if (IP_BIT_ISFALSE(flags, IPCOM_SYSVAR_FLAG_OVERWRITE)) { Ip_size_t test_size = 1; char test[1]; if (ipcom_sysvar_get_ose5(name, test, &test_size) || test_size > 1) return IPCOM_ERR_DUPLICATE; } #endif /* IP_PORT_OSE5 */ retval = ipcom_once(&ipcom_sysvar_once, ipcom_sysvar_init, IP_NULL); if (retval != IPCOM_SUCCESS) { IP_PANIC(); return retval; } IPCOM_CODE_LOCK(); tree = ipcom_sysvar_tree_get(vr); if (tree == IP_NULL) retval = IPCOM_ERR_NO_MEMORY; else retval = ipcom_sysvar_set_tree(name, value, flags, tree); ipcom_sysvar_tree_done(tree); IPCOM_CODE_UNLOCK(); return retval; }
/* *=========================================================================== * ipcom_drv_eth_filter_pkt_to_me *=========================================================================== * Description: Returns if this packet was sent to this node. * Parameters: filter - The current filter for this interface. * frame - An Ethernet frame. * Returns: IP_TRUE if this packet was sent to this node. * */ IP_PUBLIC Ip_bool ipcom_drv_eth_filter_pkt_to_me(Ipcom_drv_eth_filter *filter, Ipcom_eth_hdr *frame) { int i; if (filter->promisc) /* Driver in software-promiscuous mode, accept all packets. */ return IP_TRUE; if (frame->dst[0] == 0xFF) /* Ethernet broadcast is always accepted */ return IP_TRUE; if (IP_BIT_ISFALSE(frame->dst[0], 0x01)) { /* Unicast packet */ if (ipcom_memcmp(filter->unicast_addr, frame->dst, IPCOM_DRV_ETH_ADDR_SIZE) != 0) /* Not my MAC address */ return IP_FALSE; #ifdef IPCOM_USE_INET if (filter->in_block_addr.s_addr && ip_ntohs(frame->type) == 0x0800 && ipcom_memcmp(&filter->in_block_addr, &frame->data[16], 4) == 0) /*lint !e416 !e420 */ return IP_FALSE; #endif return IP_TRUE; } /* Check multicast groups */ for (i = 0; i < IPCOM_DRV_ETH_MAX_MULTIADDR; i++) if (filter->ref[i] != 0 && ipcom_memcmp(filter->mcast_addr[i], frame->dst, IPCOM_DRV_ETH_ADDR_SIZE) == 0) return IP_TRUE; /* This multicast frame was not sent to this interface */ return IP_FALSE; }
/* *=========================================================================== * ipnet_loopback_ip_output *=========================================================================== * Description: Updates statistics counter and add the link trailer. * Parameters: netif - The interface the packet was sent to. * rt - The route followed (ignored). * pkt - The packet to loopback. pkt->start is the offset to the * IP header. * Returns: 0 = success, 0< = error code. * */ IP_STATIC int ipnet_loopback_ip_output(Ipnet_netif *netif, Ipnet_route_entry *rt, Ipcom_pkt *pkt) { Ipnet_loopback_trailer_t *tr; IPCOM_UNUSED_ARG(rt); if (IP_UNLIKELY(IP_BIT_ISFALSE(netif->ipcom.flags, IP_IFF_UP))) { ipcom_pkt_free(pkt); return -IP_ERRNO_EHOSTDOWN; } #ifdef IPCOM_ZEROCOPY pkt = ipcom_pkt_make_linear(pkt); if (IP_UNLIKELY(pkt == IP_NULL)) /* Not enough packets to make this packet linear, not much to about it */ return 0; #endif /* IPCOM_ZEROCOPY */ IP_BIT_CLR(pkt->flags, IPCOM_PKT_FLAG_OUTPUT); #if defined(IPCOM_USE_INET) || defined(IPCOM_USE_INET6) ip_assert2((pkt->data[pkt->start] & 0xf0) == 0x40 || (pkt->data[pkt->start] & 0xf0) == 0x60); #elif defined(IPCOM_USE_INET) ip_assert2((pkt->data[pkt->start] & 0xf0) == 0x40); #else ip_assert2((pkt->data[pkt->start] & 0xf0) == 0x60); #endif tr = (Ipnet_loopback_trailer_t *) &pkt->data[pkt->end]; IP_SET_32ON8(&tr->scope_id, pkt->ifindex); pkt->ifindex = netif->ipcom.ifindex; return ipnet_if_output(netif, pkt); }
/* *=========================================================================== * ipcom_sysvar_set_internal *=========================================================================== * Description: * Parameters: * Returns: */ IP_GLOBAL Ip_err ipcom_sysvar_set_tree(const char *name, const char *value, int flags, Ipcom_sysvar_tree *tree) { Ip_size_t name_length; Ip_size_t value_length; Ipcom_sysvar_entry *sysvar; Ip_err retval = IPCOM_SUCCESS; /* Check for duplicate. */ sysvar = ipcom_hash_get(tree->sysvars, name); if (sysvar) { if (IP_BIT_ISSET(sysvar->flags, IPCOM_SYSVAR_FLAG_READONLY)) { retval = IPCOM_ERR_READONLY; goto leave; } else if (IP_BIT_ISFALSE(flags, IPCOM_SYSVAR_FLAG_OVERWRITE)) { retval = IPCOM_ERR_DUPLICATE; goto leave; } else { flags |= sysvar->flags & IPCOM_SYSVAR_FLAG_KERNEL; ipcom_hash_remove(tree->sysvars, sysvar); ipcom_free(sysvar); goto set; } } /* No current entry found and not allowed to create a new entry. */ if(IP_BIT_ISSET(flags, IPCOM_SYSVAR_FLAG_NOCREATE)) { retval = IPCOM_ERR_FAILED; goto leave; } /* Add the new sysvar. */ set: name_length = ipcom_strlen(name) + 1; value_length = ipcom_strlen(value) + 1; sysvar = ipcom_malloc(sizeof(Ipcom_sysvar_entry) + name_length + value_length); if(sysvar == IP_NULL) { retval = IPCOM_ERR_NO_MEMORY; goto leave; } sysvar->refcount = 1; sysvar->flags = flags; if (IP_BIT_ISFALSE(flags, IPCOM_SYSVAR_FLAG_INIT)) { tree->modified = IP_TRUE; sysvar->flags |= IPCOM_SYSVAR_FLAG_MODIFIED; } sysvar->name = (const char *)sysvar + sizeof(Ipcom_sysvar_entry); ipcom_memcpy((void *)sysvar->name, name, name_length); sysvar->value = sysvar->name + name_length; ipcom_memcpy((void *)sysvar->value, value, value_length); retval = ipcom_hash_add(tree->sysvars, sysvar); leave: return retval; /*lint !e429 Custodial pointer 'sysvar' has not been freed or returned */ }
/* *=========================================================================== * ipnet_rtnetlink_route_newroute_family *=========================================================================== * Description: Add a new rotue via NETLINK. * Parameters: data - Message payload * len - Length of message. * nlh - NETLINK message header * arg - Reference to route attributes. * * Returns: 0 - Success * <0 - Failure * */ IP_GLOBAL int ipnet_rtnetlink_route_newroute_family(Ipnet_netlink_mem_t *mem, struct Ip_nlmsghdr *nlh, struct Ip_rtattr **rta, int family) { Ipnet_netif *netif = IP_NULL; Ipnet_ppp_peer *p = IP_NULL; int ret = -1; Ip_u16 vr; Ip_u32 table; Ip_bool is_multipath_route = IP_FALSE; Ip_ssize_t mpa_size = 0; struct Ip_rtnexthop *nh = IP_NULL; struct Ipnet_rt_metrics metrics; struct Ip_sockaddr *gw = IP_NULL; void *mask = IP_NULL; struct Ip_sockaddr_dl gw_dl; struct Ipnet_route_add_param param; struct Ip_rtmsg *rtm = IP_NLMSG_DATA(nlh); union Ip_sockaddr_union ugw; Ipnet_rtnetlink_key_t ukey; #ifdef IPMPLS struct Ip_sockaddr_mpls gw_mpls; #endif /* IPMPLS */ #ifdef IPNET_USE_ROUTE_COOKIES Ipnet_rt_cookie cookie; #endif /* IPNET_USE_ROUTE_COOKIES */ table = IPCOM_ROUTE_TABLE_GET(rtm->rtm_table); /* Prepare route parameters */ ipcom_memset(¶m, 0, sizeof(param)); ipcom_memset(&metrics,0,sizeof(metrics)); param.flags = IPNET_RTF_STATIC | IPNET_RTF_UP | IPNET_RTF_DONE; #ifdef IPNET_USE_ROUTE_TABLE_NAMES if (rta[IP_RTA_TABLE_NAME -1]) { if (ipnet_route_vr_and_table_from_name(IP_RTA_DATA(rta[IP_RTA_TABLE_NAME - 1]), &vr, &table) < 0) return -IP_ERRNO_ESRCH; } else #endif { if (mem->vr == IPCOM_VR_ANY) return -IP_ERRNO_EINVAL; vr = ipnet_rtnetlink_vr(rta[IP_RTA_VR - 1], mem->vr); if (rta[IP_RTA_TABLE - 1]) table = IP_GET_32ON8(IP_RTA_DATA(rta[IP_RTA_TABLE - 1])); } if (rta[IP_RTA_OIF -1]) { int ifindex = 0; if (rta[IP_RTA_OIF-1]->rta_len != IP_RTA_LENGTH(sizeof(int))) return -IP_ERRNO_EINVAL; ifindex = IP_GET_32ON8(IP_RTA_DATA(rta[IP_RTA_OIF-1])); netif = ipnet_if_indextonetif(vr, ifindex); if (netif) p = netif->private_data; } if (rta[IP_RTA_MULTIPATH -1]) { is_multipath_route = IP_TRUE; nh = IP_RTA_DATA(rta[IP_RTA_MULTIPATH-1]); mpa_size = IP_RTA_PAYLOAD(rta[IP_RTA_MULTIPATH-1]); if ((nh == IP_NULL) || (mpa_size == 0)) return -IP_ERRNO_EINVAL; } if ((ret = ipnet_rtnetlink_route_key_setup(family, &ukey, netif? netif->ipcom.ifindex : 0, &mask, rtm->rtm_dst_len, rta[IP_RTA_DST-1])) < 0) return ret; if ((ret = ipnet_rtnetlink_route_gw_setup(family, netif? netif->ipcom.ifindex : 0, &ugw, &gw, rta[IP_RTA_GATEWAY-1])) < 0) return ret; #ifdef IPCOM_USE_INET if (family == IP_AF_INET) { if (gw != IP_NULL) { /* Check if it is a pure gateway or not */ if (p == IP_NULL || p->peer4.s_addr != ugw.sin.sin_addr.s_addr) param.flags |= IPNET_RTF_GATEWAY; } } else #endif #ifdef IPCOM_USE_INET6 if (family == IP_AF_INET6) { if (gw != IP_NULL) { /* Check if it is a pure gateway or not */ if (p == IP_NULL || !IP_IN6_ARE_ADDR_EQUAL(&ugw.sin6.sin6_addr, &p->peer6)) param.flags |= IPNET_RTF_GATEWAY; } } else #endif { return -IP_ERRNO_EAFNOSUPPORT; } if (!mask) param.flags |= IPNET_RTF_HOST; if (rtm->rtm_type == IP_RTN_PROXY) { /* This is a proxy arp network route */ IP_BIT_CLR(param.flags, IPNET_RTF_CLONING); IP_BIT_SET(param.flags, IPNET_RTF_PROTO2); if (rta[IP_RTA_PROXY_ARP_LLADDR - 1]) { /* This is a network proxy arp with specific lladdr */ if (netif == IP_NULL) return -IP_ERRNO_EINVAL; ipcom_memset(&gw_dl, 0, sizeof(struct Ip_sockaddr_dl)); IPCOM_SA_LEN_SET(&gw_dl, sizeof(struct Ip_sockaddr_dl)); gw_dl.sdl_family = IP_AF_LINK; gw_dl.sdl_index = (Ip_u16)netif->ipcom.ifindex; gw_dl.sdl_alen = (Ip_u8) netif->ipcom.link_addr_size; gw_dl.sdl_type = (Ip_u8) netif->ipcom.type; ipcom_memcpy(IP_SOCKADDR_DL_LLADDR(&gw_dl), IP_RTA_DATA(rta[IP_RTA_PROXY_ARP_LLADDR - 1]), IPNET_ETH_ADDR_SIZE); gw = (struct Ip_sockaddr *) &gw_dl; IP_BIT_SET(param.flags, IPNET_RTF_LLINFO); } } else if (rtm->rtm_type == IP_RTN_PROHIBIT) IP_BIT_SET(param.flags, IPNET_RTF_REJECT); else if (rtm->rtm_type == IP_RTN_THROW) IP_BIT_SET(param.flags, IPNET_RTF_SKIP); else if (rtm->rtm_type == IP_RTN_UNREACHABLE) { if (netif == IP_NULL) netif = ipnet_loopback_get_netif(vr); IP_BIT_CLR(param.flags, IPNET_RTF_UP); } else if (rtm->rtm_type == IP_RTN_CLONE) IP_BIT_SET(param.flags, IPNET_RTF_CLONING); else if (rtm->rtm_type == IP_RTN_BLACKHOLE) IP_BIT_SET(param.flags, IPNET_RTF_BLACKHOLE); #ifdef IPMPLS /* Check for IPNET MPLS pseudo-wire route */ if (rta[IP_RTA_NH_PROTO-1]) { Ip_u32 nh_type; if (rta[IP_RTA_NH_PROTO-1]->rta_len != IP_RTA_LENGTH(sizeof(Ip_u32))) return -IP_ERRNO_EINVAL; if (rta[IP_RTA_NH_PROTO_DATA-1]->rta_len != IP_RTA_LENGTH(sizeof(Ip_u32))) return -IP_ERRNO_EINVAL; ipcom_memcpy(&nh_type, IP_RTA_DATA(rta[IP_RTA_NH_PROTO-1]), sizeof(Ip_u32)); if (nh_type != IPNET_ETH_P_MPLS_UNICAST) return -IP_ERRNO_EINVAL; ipcom_memset(&gw_mpls, 0, sizeof(gw_mpls)); gw_mpls.smpls_family = IP_AF_MPLS; IPCOM_SA_LEN_SET(&gw_mpls, sizeof (struct Ip_sockaddr_mpls)); ipcom_memcpy(&gw_mpls.smpls_key, IP_RTA_DATA(rta[IP_RTA_NH_PROTO_DATA-1]), sizeof(Ip_u32)); IP_BIT_CLR(param.flags,IPNET_RTF_GATEWAY); gw = (struct Ip_sockaddr *)&gw_mpls; } else { /* Check if cloning flag shall be set */ if (IP_BIT_ISFALSE(param.flags, IPNET_RTF_HOST | IPNET_RTF_GATEWAY | IPNET_RTF_REJECT | IPNET_RTF_BLACKHOLE)) IP_BIT_SET(param.flags, IPNET_RTF_CLONING); } #endif if (rta[IP_RTA_METRICS-1]) { int rlen = (int)IP_RTA_PAYLOAD(rta[IP_RTA_METRICS-1]); Ip_u32 dummy = 0; struct Ip_rtattr *rtax = (struct Ip_rtattr*)IP_RTA_DATA(rta[IP_RTA_METRICS-1]); metrics.rmx_expire = IPCOM_ADDR_INFINITE; param.metrics = &metrics; for(;rlen > 0; rlen -= (int)rtax->rta_len,rtax = IP_RTA_NEXT(rtax,dummy)) { switch (rtax->rta_type) { case IP_RTAX_MTU: ipcom_memcpy(&metrics.rmx_mtu, IP_RTA_DATA(rtax), sizeof(Ip_u32)); break; case IP_RTAX_RTT: ipcom_memcpy(&metrics.rmx_rtt, IP_RTA_DATA(rtax), sizeof(Ip_u32)); break; case IP_RTAX_RTTVAR: ipcom_memcpy(&metrics.rmx_rttvar, IP_RTA_DATA(rtax), sizeof(Ip_u32)); break; } } } #ifdef IPNET_USE_ROUTE_COOKIES if (rta[IP_RTA_COOKIE-1]) { if (IP_RTA_PAYLOAD(rta[IP_RTA_COOKIE-1]) > sizeof(cookie)) return -IP_ERRNO_EINVAL; ipcom_memset(&cookie, 0, sizeof(cookie)); ipcom_memcpy(&cookie, IP_RTA_DATA(rta[IP_RTA_COOKIE-1]), IP_RTA_PAYLOAD(rta[IP_RTA_COOKIE-1])); param.cookie = &cookie; } #endif /* IPNET_USE_ROUTE_COOKIES */ while (1) { if (is_multipath_route && (gw == IP_NULL)) { netif = ipnet_if_indextonetif(vr, nh->rtnh_ifindex); metrics.rmx_hopcount = nh->rtnh_hops; metrics.rmx_expire = IPCOM_ADDR_INFINITE; param.metrics = &metrics; if (nh->rtnh_len > sizeof(struct Ip_rtnexthop)) { /* Multihop route has gateway */ IP_BIT_CLR(param.flags, IPNET_RTF_CLONING); IP_BIT_SET(param.flags, IPNET_RTF_GATEWAY); if ((ret = ipnet_rtnetlink_route_gw_setup(family, netif? netif->ipcom.ifindex : 0, &ugw, &gw, IP_RTNH_DATA(nh))) < 0) return ret; } mpa_size -= IP_RTNH_ALIGN(nh->rtnh_len); if (mpa_size > 0) nh = IP_RTNH_NEXT(nh); } param.domain = family; param.vr = vr; param.table = table; param.netif = netif; param.key = &ukey; param.netmask = mask; param.gateway = gw; param.pid = mem->pid; param.seq = nlh->nlmsg_seq; param.no_ref_count = IP_TRUE; /* Try to add the route */ if (netif) IPNET_IF_LOCK(netif); ret = ipnet_route_add(¶m); if (netif != IP_NULL) IPNET_IF_UNLOCK(netif); if (is_multipath_route) { gw = IP_NULL; if (ret < 0 && ret != -IP_ERRNO_EEXIST) goto rollback; if (mpa_size == 0) { ret = 0; break; } else if (mpa_size < 0) { /* Malformed packet */ ret = -IP_ERRNO_EINVAL; goto rollback; } } else break; } return ret; rollback: (void)ipnet_rtnetlink_route_delroute_family(mem, nlh, rta, family); return ret; }
/* *=========================================================================== * ipnet_rtnetlink_route_foreach_vr *=========================================================================== * Description: Hash table foreach callback. Called once for each virtual * router that exists in the system. * Parameters: rtab - route table * param - callback parameters. * Returns: - * */ IP_STATIC void ipnet_rtnetlink_route_foreach_vr_family(Ipcom_route *rtab, Ipnet_rtnetlink_route_family_t *param) { int new_offs = 0; Ip_ptrdiff_t table = IPNET_ROUTE_GET_TABLE(rtab); Ip_u16 vr = IPNET_ROUTE_GET_VR(rtab); Ipnet_route_entry *rt = IP_NULL; /* This traversal is already aborted */ if (param->state.aborted) return; /* Only handle rtabs of selected address family */ if (IPNET_ROUTE_GET_FAMILY(rtab) != param->family) return; /* Check if specific VR shall be dumped */ if (IP_BIT_ISFALSE(param->nlmsg->nlmsg_flags, IP_NLM_F_VR_UNSPEC) && (param->mem->vr != IPCOM_VR_ANY) && (param->mem->vr != vr)) return; /* * If this is a trailer message buffer, make sure it * starts dumping where the last message ended */ if (param->state.cont) { Ipnet_route_entry *rtt = (Ipnet_route_entry*)(*param->state.rt); /* Verify current state */ if (*param->state.vr != vr || *param->state.table != table) return; if (rtt != IP_NULL) { rt = ipnet_route_first_entry(IPNET_ROUTE_GET_FAMILY(rtab), vr, table); while (rt != IP_NULL) { if (rt == rtt) break; rt = ipnet_route_next_entry(rt); } } } /* Reset the continue variable; we're on the move again */ param->state.cont = 0; /* Get first unless we've found one to continue from */ if (rt == IP_NULL) rt = ipnet_route_first_entry(IPNET_ROUTE_GET_FAMILY(rtab), vr, table); /* */ while (rt) { /* Do not dump the 255.255.255.255, 224.0.0.0/4 or IPv6 multicast routes. */ /* Do not dump routes that are part of multipath routes either */ if (IP_BIT_ISFALSE(rt->hdr.flags, IPNET_RTF_X_MCAST_RO | IPNET_RTF_X_BCAST_RO | IPNET_RTF_X_HIDDEN) && (rt->prev == IP_NULL)) { #ifdef IPCOM_USE_INET if (param->family == IP_AF_INET) { new_offs = ipnet_rtnetlink_ip4_route_fill_info (param->mem, rt, param->nlmsg->nlmsg_seq, IP_RTM_NEWROUTE, IP_NLM_F_MULTI); } else #endif #ifdef IPCOM_USE_INET6 if (param->family == IP_AF_INET6) { new_offs = ipnet_rtnetlink_ip6_route_fill_info (param->mem, rt, param->nlmsg->nlmsg_seq, IP_RTM_NEWROUTE, IP_NLM_F_MULTI); } else #endif { IP_PANIC(); } if (new_offs < 0) goto aborted; } rt = ipnet_route_next_entry(rt); /* */ if (rt && new_offs) goto aborted; } return; aborted: param->state.aborted = 1; *param->state.rt = (Ip_ptrdiff_t)rt; *param->state.table = (Ip_ptrdiff_t)table; *param->state.vr = (Ip_ptrdiff_t)vr; }
/* *=========================================================================== * ipnet_udp_input *=========================================================================== * Description: Input handler for packet to UDP sockets. This function will * NOT free the packet if the operation fails. * Parameters: pkt - The received packet, must be freed by the called if * this function fails. * is_multicast - Set to IP_TRUE if the packet was sent to a * multicast address. * proto - The protocol number. * src_addr - The address (Ipv4 or IPv6) of the sender. * dst_addr - The address (Ipv4 or IPv6) of the receiver (this system). * socklookup - A pointer to a function that can return the socket * that is associated with this packet. * nat_t - NAT traversal; if used. * Returns: 0 >= number of matching sockets, <0 = error code * */ IP_GLOBAL int ipnet_udp_input(Ipcom_pkt *pkt, Ip_bool is_multicast, IP_CONST void* src_addr, IP_CONST void* dst_addr, Ipnet_sock_lookup_f socklookup, int *nat_t) { Ipnet_pkt_udp *udp_hdr; int retval; int ulen_h; Ipnet_socket *sock; Ip_u16 src_port; Ip_u16 dst_port; Ip_bool pkt_no_rx_cache; IPCOM_WV_MARKER_1 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_VERBOSE, 1, 3, IPCOM_WV_NETDEVENT_START, ipnet_udp_input, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input++); IPCOM_PKT_TRACE(pkt, IPCOM_PKT_ID_UDP_INPUT); if (IP_UNLIKELY(pkt->end - pkt->start < IPNET_UDP_HDR_SIZE)) { IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_WARNING, 1, 4, IPCOM_WV_NETDEVENT_WARNING, IPCOM_WV_NETD_RECV, ipnet_udp_input, IPCOM_WV_NETD_BADHLEN, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input_hdr_trunc++); IPCOM_MIB2(udpInErrors++); return -IP_ERRNO_EINVAL; } udp_hdr = (Ipnet_pkt_udp*) &pkt->data[pkt->start]; ulen_h = ip_ntohs(udp_hdr->ulen); src_port = ip_ntohs(udp_hdr->sport); dst_port = ip_ntohs(udp_hdr->dport); if (IP_UNLIKELY(pkt->end - pkt->start < ulen_h)) { IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_WARNING, 1, 5, IPCOM_WV_NETDEVENT_WARNING, IPCOM_WV_NETD_RECV, ipnet_udp_input, IPCOM_WV_NETD_BADLEN, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input_hdr_trunc++); IPCOM_MIB2(udpInErrors++); return -IP_ERRNO_EINVAL; } pkt->end = pkt->start + ulen_h; if (udp_hdr->sum != 0 && IP_BIT_ISFALSE(pkt->flags, IPCOM_PKT_FLAG_LOOPED_BACK)) { Ip_u16 chksum; /* Only check packets that was not created locally */ #ifdef IPCOM_USE_HW_CHECKSUM_RX if (IP_BIT_ISSET(pkt->flags, IPCOM_PKT_FLAG_HW_CHECKSUM)) chksum = 0; else if (IP_BIT_ISSET(pkt->flags, IPCOM_PKT_FLAG_TL_CHECKSUM)) chksum = ipcom_in_checksum_finish(pkt->chk); else #endif /* IPCOM_USE_HW_CHECKSUM_RX */ { pkt->chk += ipcom_in_checksum_update(&pkt->data[pkt->start], (Ip_size_t) ulen_h); chksum = ipcom_in_checksum_finish(pkt->chk); } if (IP_UNLIKELY(chksum != 0)) { /* Wrong checksum */ IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_WARNING, 1, 6, IPCOM_WV_NETDEVENT_WARNING, IPCOM_WV_NETD_RECV, ipnet_udp_input, IPCOM_WV_NETD_BADSUM, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input_badchksum++); IPCOM_MIB2(udpInErrors++); return -IP_ERRNO_EINVAL; } } /* Move the start to beginning of application data */ pkt->start += IPNET_UDP_HDR_SIZE; if (is_multicast) { IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_INFO, 1, 7, IPCOM_WV_NETDEVENT_INFO, IPCOM_WV_NETD_RECV, ipnet_udp_input, IPCOM_WV_NETD_INFO_RECEIVE, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input_multicast++); retval = ipnet_raw_input(pkt, IP_FALSE, IP_IPPROTO_UDP, src_addr, src_port, dst_addr, dst_port, socklookup); if (retval >= 0) { /* The packet must be freed unlesss an error occured */ ipcom_pkt_free(pkt); IPCOM_MIB2(udpInDatagrams++); IPCOM_MIB2_U64_INC(udpHCInDatagrams); } else { IPCOM_MIB2(udpInErrors++); } return retval; } sock = socklookup(pkt->vr_index, IP_IPPROTO_UDP, dst_addr, dst_port, src_addr, src_port); if (sock == IP_NULL) /* No matching socket, try the wildcard group */ sock = socklookup(IPCOM_VR_ANY, IP_IPPROTO_UDP, dst_addr, dst_port, src_addr, src_port); if (sock != IP_NULL) { Ipcom_socket_eventcb event_cb = sock->ipcom.event_cb; /* Verify NAT traversal */ if (IP_UNLIKELY(ipnet_udp_encapsulation(sock, pkt, nat_t))) { ipcom_pkt_set_info(pkt, IPNET_PKT_INFO_ENCAP_UDP, sizeof(*udp_hdr), udp_hdr); pkt->start -= IPNET_UDP_HDR_SIZE; return 0; } IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_INFO, 1, 8, IPCOM_WV_NETDEVENT_INFO, IPCOM_WV_NETD_RECV, ipnet_udp_input, IPCOM_WV_NETD_INFO_RECEIVE, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input_sock_match++); pkt->fd = sock->ipcom.fd; pkt_no_rx_cache = IP_BIT_ISSET(pkt->flags, IPCOM_PKT_FLAG_NO_RX_CACHE); retval = ipnet_queue_received_packet(pkt, sock); if (retval < 0) { IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_WARNING, 1, 9, IPCOM_WV_NETDEVENT_WARNING, IPCOM_WV_NETD_RECV, ipnet_udp_input, IPCOM_WV_NETD_INFO_QUEUE_FULL, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input_queue_pkt_err++); IPCOM_MIB2(udpInErrors++); return retval; } IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_INFO, 1, 10, IPCOM_WV_NETDEVENT_INFO, IPCOM_WV_NETD_RECV, ipnet_udp_input, IPCOM_WV_NETD_INFO_RECEIVE, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input_queue_pkt_ok++); if (event_cb != IP_NULL) event_cb(&sock->ipcom, pkt, IP_SOEVENT_CB_INPKT); IPCOM_MIB2(udpInDatagrams++); IPCOM_MIB2_U64_INC(udpHCInDatagrams); if (IP_BIT_ISFALSE(sock->flags, IPNET_SOCKET_FLAG_RX_CACHED) && !pkt_no_rx_cache) ipnet_sock_add_to_rx_cache(sock, src_addr, src_port, dst_addr, dst_port, ipnet_udp_fast_deliver_data); return 1; } else { IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_WARNING, 1, 13, IPCOM_WV_NETDEVENT_WARNING, IPCOM_WV_NETD_RECV, ipnet_udp_input, IPCOM_WV_NETD_NOPORT, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input_sock_nomatch++); IPCOM_MIB2(udpNoPorts++); } IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_WARNING, 1, 14, IPCOM_WV_NETDEVENT_WARNING, IPCOM_WV_NETD_RECV, ipnet_udp_input, IPCOM_WV_NETD_NOPORT, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_input_econnrefused++); return -IP_ERRNO_ECONNREFUSED; }
/* *=========================================================================== * ipnet_sock_udp_send *=========================================================================== * Description: Adds a UDP header to the application data. * Parameters: sock - The socket to use when sending. * msg - The send parameters. * pkt - Packet that contains the UDP payload. * Returns: ==0 = success, <0 = error code. * */ IP_STATIC int ipnet_sock_udp_send(Ipnet_socket *sock, IP_CONST struct Ip_msghdr *msg, Ipcom_pkt *pkt) { Ipnet_sock_udp_ops *ops = (Ipnet_sock_udp_ops *) sock->ops; Ip_u16 to_port_n; Ipnet_pkt_udp *udp; int ret; IPCOM_WV_MARKER_1 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_VERBOSE, 1, 1, IPCOM_WV_NETDEVENT_START, ipnet_sock_udp_send, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_output++); ip_assert(sock->ipcom.type == IP_SOCK_DGRAM); ip_assert(sock->proto == IP_IPPROTO_UDP); if (msg->msg_name == IP_NULL) to_port_n = ip_htons(sock->dport); else /* Ok for both IPv4 and IPv6 */ to_port_n = ((struct Ip_sockaddr_in*) msg->msg_name)->sin_port; pkt->start -= IPNET_UDP_HDR_SIZE; /* Fill in UDP header. */ udp = (Ipnet_pkt_udp *)&pkt->data[pkt->start]; if (sock->sport) udp->sport = ip_htons(sock->sport); else { /* UDP socket unbound, get a temporary port. */ udp->sport = ipnet_next_ephemeral_port(sock); if (udp->sport == 0) { IPCOM_WV_EVENT_2 (IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_WARNING, 1, 2, IPCOM_WV_NETDEVENT_WARNING, IPCOM_WV_NETD_SEND, ipnet_sock_udp_send, IPCOM_WV_NETD_ADDRINUSE, IPCOM_WV_IPNET_UDP_MODULE, IPCOM_WV_NETD_UDP4); IPNET_STATS(udp_output_eaddrinuse++); ret = -IP_ERRNO_EADDRINUSE; goto errout; } udp->sport = ip_htons(udp->sport); } udp->dport = to_port_n; udp->sum = 0; #ifdef IPCOM_ZEROCOPY udp->ulen = (Ip_u16) ip_htons(ipcom_pkt_get_length(pkt)); #else udp->ulen = (Ip_u16) ip_htons(pkt->end - pkt->start); #endif /* Update the checksum with the UDP header */ #ifdef IPCOM_USE_HW_CHECKSUM_TX if (IP_BIT_ISFALSE(pkt->flags, IPCOM_PKT_FLAG_HW_CHECKSUM)) #endif #ifdef IPCOM_ZEROCOPY if (IP_BIT_ISFALSE(msg->msg_flags, IP_MSG_ZBUF)) #endif pkt->chk += ipcom_in_checksum_update(&pkt->data[pkt->start], IPNET_UDP_HDR_SIZE); IPCOM_MIB2(udpOutDatagrams++); IPCOM_MIB2_U64_INC(udpHCOutDatagrams); return ops->inet.network_send(sock, msg, pkt); errout: ipcom_pkt_free(pkt); return ret; }
/* *=========================================================================== * ipnet_ip_mib_cb_ipCidrRouteTable *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC Ip_bool ipnet_ip_mib_cb_ipCidrRouteTable(Ipnet_route_entry *rt, Ipsnmp_route_walk *rwp) { Ip_s32 tmp, lex, len = 0; /* Early exit if exact match was found previously */ if(rwp->bestrt != IP_NULL && (rwp->cmd == IPSNMP_MIB_COMMAND_GET || rwp->cmd == IPSNMP_MIB_COMMAND_TEST || rwp->cmd == IPSNMP_MIB_COMMAND_SET)) goto exit; if(rt->netif == IP_NULL) goto exit; /* Do not use hidden entries */ if(IP_BIT_ISSET(rt->hdr.flags, IPNET_RTF_X_HIDDEN)) goto exit; /* Route must be usable */ if(IP_BIT_ISFALSE(rt->hdr.flags, IPNET_RTF_UP)) goto exit; /* Do not use link layer entries */ if(IP_BIT_ISSET(rt->hdr.flags, IPNET_RTF_LLINFO)) goto exit; /* Do not use loopback entries */ if (IP_BIT_ISSET(rt->netif->ipcom.flags, IP_IFF_LOOPBACK)) goto exit; ip_assert(rt->hdr.key != IP_NULL); /* Do not use multicast entries */ if(IP_IN_CLASSD(*(Ip_u32 *)rt->hdr.key)) goto exit; /* Do not use broadcast entries */ if(ip_ntohl(*(Ip_u32 *)rt->hdr.key) == IP_INADDR_BROADCAST) goto exit; if(rwp->count_only == IP_TRUE) { count++; goto exit; } rwp->buf[0] = '\0'; /* ipCidrRouteDest */ if(ipcom_inet_ntop(IP_AF_INET, rt->hdr.key, &rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len) == IP_NULL) goto exit; len = ipcom_strlen(rwp->buf); if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, ".") < 0) goto exit; len = ipcom_strlen(rwp->buf); /* ipCidrRouteMask */ if(rt->hdr.mask == IP_NULL) { if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "255.255.255.255") < 0) goto exit; } else { if(ipcom_inet_ntop(IP_AF_INET, rt->hdr.mask, &rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len) == IP_NULL) goto exit; } len = ipcom_strlen(rwp->buf); if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, ".") < 0) goto exit; len = ipcom_strlen(rwp->buf); /* ipCidrRouteTos */ tmp = 0; if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "%d.", (int)tmp) < 0) goto exit; len = ipcom_strlen(rwp->buf); /* ipCidrRouteNextHop */ if(IP_BIT_ISSET(rt->hdr.flags, IPNET_RTF_GATEWAY)) { struct Ip_sockaddr_in *sa; ip_assert(rt->gateway != IP_NULL); sa = (struct Ip_sockaddr_in *)rt->gateway; if(ipcom_inet_ntop(IP_AF_INET, &sa->sin_addr.s_addr, &rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID - len) == IP_NULL) goto exit; } else { if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "0.0.0.0") < 0) goto exit; } len = ipcom_strlen(rwp->buf); if(ipcom_snprintf(&rwp->buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, ".") < 0) goto exit; len = ipcom_strlen(rwp->buf); if(len) rwp->buf[len-1] = '\0'; lex = ipsnmp_util_lexcmp_oid(rwp->buf, rwp->id); if(rwp->cmd == IPSNMP_MIB_COMMAND_NEXT) { if(lex > 0) { if(rwp->bestrt == IP_NULL || ipsnmp_util_lexcmp_oid(rwp->buf, rwp->best) < 0) { ipcom_strcpy(rwp->best, rwp->buf); rwp->bestrt = rt; } } } else { if(lex == 0) { ipcom_strcpy(rwp->best, rwp->buf); rwp->bestrt = rt; } } exit: /* Do not delete the entry */ return IP_FALSE; }
/* *=========================================================================== * ipnet_fragment_packet *=========================================================================== * Description: Splits a packet that is to big to fit into the MTU of the * network interface. * Parameters: pkt - The packet to split. pkt->start is the offset to the * extension header (or transport layer protocol) with the * id of 'next_hdr'. This packet is released by this function. * ip_hdr_size - The size of the IP header. * other_hdr_size - The size of other headers that will be * added due to fragmentation. * mtu - The MTU of the network interface. * has_more_fragments - function that returns IP_TRUE if the * packet passed as an argument has more fragments. This * parameter might be IP_NULL. * Returns: A list of fragments or IP_NULL if not enough memory could * be allocated to create all fragments. */ IP_GLOBAL Ipcom_pkt * ipnet_fragment_packet(Ipcom_pkt *pkt, int ip_hdr_size, int other_hdr_size, int mtu, Ipnet_more_fragments_func more_fragments) { Ipcom_pkt *frag_pkt_head; Ipcom_pkt *frag_pkt_tail; Ipcom_pkt *frag_pkt; int frag_size; int total_size; int size_of_this_fragment; int frag_offset; Ipnet_pkt_info_sock_snd_buf *ssb; total_size = pkt->end - pkt->start; frag_size = (mtu - ip_hdr_size - other_hdr_size) & 0xfff8; frag_pkt_head = IP_NULL; frag_pkt_tail = IP_NULL; frag_offset = 0; while (frag_offset < total_size) { if (total_size - frag_offset > frag_size) size_of_this_fragment = frag_size; else size_of_this_fragment = total_size - frag_offset; frag_pkt = ipcom_pkt_malloc(mtu, IP_FLAG_FC_STACKCONTEXT); if (frag_pkt == IP_NULL) { IPCOM_WV_MARKER_1 ( IPCOM_WV_NETD_IP4_DATAPATH_EVENT, IPCOM_WV_NETD_CRITICAL, 1, 1, IPCOM_WV_NETD_NOBUFS, ipnet_fragment_packet, IPCOM_WV_IPNET_FRAG_MODULE, IPCOM_WV_NETD_IP_REASSEMBLE); IPNET_STATS(pkt_frag_nomem++); ipcom_pkt_free(pkt); if (frag_pkt_head != IP_NULL) ipcom_pkt_free(frag_pkt_head); return IP_NULL; } #ifdef IPCOM_USE_MIB2 if(other_hdr_size == 0) { #ifdef IPCOM_USE_INET Ipnet_netif *netif = ipnet_if_indextonetif(pkt->vr_index, pkt->ifindex); IPCOM_MIB2(ipFragCreates++); if (netif != IP_NULL) { IPCOM_MIB2_SYSWI_U32_ADD(v4, ipSystemStatsOutFragCreates, 1); IPCOM_MIB2_PERIF_U32_ADD(v4, ipIfStatsOutFragCreates, 1, netif); } #endif } else { #ifdef IPCOM_USE_INET6 Ipnet_netif *netif = ipnet_if_indextonetif(pkt->vr_index, pkt->ifindex); IPCOM_MIB2_NETIF(ipv6IfStatsOutFragCreates++); if (netif != IP_NULL) { IPCOM_MIB2_SYSWI_U32_ADD(v6, ipSystemStatsOutFragCreates, 1); IPCOM_MIB2_PERIF_U32_ADD(v6, ipIfStatsOutFragCreates, 1, netif); } #endif } #endif /* IPCOM_USE_MIB2 */ if (frag_pkt_head == IP_NULL) frag_pkt_head = frag_pkt; else frag_pkt_tail->next_fragment = frag_pkt; frag_pkt_tail = frag_pkt; IPCOM_PKT_TRACE(frag_pkt, IPCOM_PKT_ID_FRAG); frag_pkt->fd = pkt->fd; frag_pkt->ifindex = pkt->ifindex; frag_pkt->flags = pkt->flags; frag_pkt->vr_index = pkt->vr_index; /* Copy IP packet payload */ frag_pkt->start = (frag_pkt->maxlen - size_of_this_fragment) & ~0x3; frag_pkt->end = frag_pkt->start + size_of_this_fragment; ip_assert(frag_pkt->start < frag_pkt->maxlen); ipcom_memcpy(&frag_pkt->data[frag_pkt->start], &pkt->data[pkt->start + frag_offset], (Ip_size_t)size_of_this_fragment); frag_pkt->offset = (Ip_u16) (frag_offset + pkt->offset); frag_offset += size_of_this_fragment; IP_BIT_SET(frag_pkt->flags, IPCOM_PKT_FLAG_MORE_FRAG); } if (IP_BIT_ISFALSE(pkt->flags, IPCOM_PKT_FLAG_FRAGMENT) || (more_fragments && IP_FALSE == more_fragments(pkt))) /* This is either an IP datagram sourced from this node or the last fragment of an IP datagram that has been forwarded by this node. */ IP_BIT_CLR(frag_pkt_tail->flags, IPCOM_PKT_FLAG_MORE_FRAG); ip_assert(pkt->start + frag_offset == pkt->end); ip_assert(frag_pkt_head != IP_NULL); if (IP_NULL != (ssb = ipcom_pkt_get_info(pkt, IPNET_PKT_INFO_SOCK_SND_BUF))) { /* Transfer the socket send buffer allocation from the original packet to the last fragment to make sure that the send flow control is still driven by TX done events. */ ipcom_pkt_set_info(frag_pkt_tail, IPNET_PKT_INFO_SOCK_SND_BUF, sizeof(Ipnet_pkt_info_sock_snd_buf), ssb); frag_pkt_tail->dtor = pkt->dtor; pkt->dtor = IP_NULL; } /* Do not free original yet, since it might hold the callers signal buffer. Put it in the fragment tails next original instead and it will be freed when the last segment has been transmitted */ if (frag_pkt_tail != IP_NULL) frag_pkt_tail->next_original = pkt; else ipcom_pkt_free(pkt); return frag_pkt_head; }
/* *=========================================================================== * ipnet_rtnetlink_route_foreach_vr *=========================================================================== * Description: Hash table foreach callback. Called once for each virtual * router that exists in the system. * Parameters: rtab - route table * param - callback parameters. * Returns: - * */ IP_STATIC void ipnet_rtnetlink_neigh_foreach_vr_family(Ipcom_route *rtab, Ipnet_rtnetlink_neigh_family_t *param) { Ip_u16 vr = IPNET_ROUTE_GET_VR(rtab); Ipnet_route_entry *rt = IP_NULL; /* This traversal is already aborted */ if (param->state.aborted) return; /* Only handle rtabs of selected address family */ if (param->family != IP_AF_UNSPEC && IPNET_ROUTE_GET_FAMILY(rtab) != param->family) return; /* We only have neigh values in the default table */ if (IPNET_ROUTE_GET_TABLE(rtab) != IPCOM_ROUTE_TABLE_DEFAULT) return; /* Check if specific VR shall be dumped */ if (IP_BIT_ISFALSE(param->nlmsg->nlmsg_flags, IP_NLM_F_VR_UNSPEC) && (param->mem->vr != IPCOM_VR_ANY) && (param->mem->vr != vr)) return; /* * If this is a trailer message buffer, make sure it * starts dumping where the last message ended */ if (param->state.cont) { Ipnet_route_entry *rtt = (Ipnet_route_entry*)(*param->state.rt); /* Verify current state */ if (*param->state.vr != vr) return; if (rtt != IP_NULL) { rt = ipnet_route_first_entry(IPNET_ROUTE_GET_FAMILY(rtab), vr, IPNET_ROUTE_GET_TABLE(rtab)); while (rt != IP_NULL) { if (rt == rtt) break; rt = ipnet_route_next_entry(rt); } } } /* Reset the continue variable; we're on the move again */ param->state.cont = 0; /* Get first unless we've found one to continue from */ if (rt == IP_NULL) rt = ipnet_route_first_entry(IPNET_ROUTE_GET_FAMILY(rtab), vr, IPNET_ROUTE_GET_TABLE(rtab)); /* */ while (rt) { do { if (ipnet_rtnetlink_neigh_is(rt)) break; rt = ipnet_route_next_entry(rt); } while (rt != IP_NULL); if (rt != IP_NULL) { int ret = 0; /* Verify this particular NC entry */ #ifdef IPCOM_USE_INET if (IPNET_ROUTE_GET_FAMILY(rtab) == IP_AF_INET) ret = ipnet_rtnetlink_ip4_neigh_fill_info(param->mem, rt, param->nlmsg->nlmsg_seq, IP_RTM_NEWNEIGH, IP_NLM_F_MULTI); #endif #ifdef IPCOM_USE_INET6 if (IPNET_ROUTE_GET_FAMILY(rtab) == IP_AF_INET6) ret = ipnet_rtnetlink_ip6_neigh_fill_info(param->mem, rt, param->nlmsg->nlmsg_seq, IP_RTM_NEWNEIGH, IP_NLM_F_MULTI); #endif if (ret < 0) goto aborted; /* Get next */ rt = ipnet_route_next_entry(rt); } } return; aborted: param->state.aborted = 1; *param->state.rt = (Ip_ptrdiff_t)rt; *param->state.vr = (Ip_ptrdiff_t)vr; }