Esempio n. 1
0
static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
{
	int n;

	if (v == SEQ_START_TOKEN) {
		seq_puts(seq,
			 "Group                            "
			 "Origin                           "
			 "Iif      Pkts  Bytes     Wrong  Oifs\n");
	} else {
		const struct mfc6_cache *mfc = v;
		const struct ipmr_mfc_iter *it = seq->private;

		seq_printf(seq,
			   NIP6_FMT " " NIP6_FMT " %-3d %8ld %8ld %8ld",
			   NIP6(mfc->mf6c_mcastgrp), NIP6(mfc->mf6c_origin),
			   mfc->mf6c_parent,
			   mfc->mfc_un.res.pkt,
			   mfc->mfc_un.res.bytes,
			   mfc->mfc_un.res.wrong_if);

		if (it->cache != &mfc_unres_queue) {
			for (n = mfc->mfc_un.res.minvif;
			     n < mfc->mfc_un.res.maxvif; n++) {
				if (MIF_EXISTS(n) &&
				    mfc->mfc_un.res.ttls[n] < 255)
					seq_printf(seq,
						   " %2d:%-3d",
						   n, mfc->mfc_un.res.ttls[n]);
			}
		}
		seq_putc(seq, '\n');
	}
	return 0;
}
static int ipv6_print_tuple(struct seq_file *s,
			    const struct nf_conntrack_tuple *tuple)
{
	return seq_printf(s, "src=" NIP6_FMT " dst=" NIP6_FMT " ",
			  NIP6(*((struct in6_addr *)tuple->src.u3.ip6)),
			  NIP6(*((struct in6_addr *)tuple->dst.u3.ip6)));
}
Esempio n. 3
0
/* Route the packet according to the routing keys specified in
 * route_info. Keys are :
 *  - ifindex : 
 *      0 if no oif preferred, 
 *      otherwise set to the index of the desired oif
 *  - route_info->gw :
 *      0 if no gateway specified,
 *      otherwise set to the next host to which the pkt must be routed
 * If success, skb->dev is the output device to which the packet must 
 * be sent and skb->dst is not NULL
 *
 * RETURN:  1 if the packet was succesfully routed to the 
 *            destination desired
 *          0 if the kernel routing table could not route the packet
 *            according to the keys specified
 */
static int 
route6(struct sk_buff *skb,
       unsigned int ifindex,
       const struct ip6t_route_target_info *route_info)
{
	struct rt6_info *rt = NULL;
	struct ipv6hdr *ipv6h = skb->nh.ipv6h;
	struct in6_addr *gw = (struct in6_addr*)&route_info->gw;

	DEBUGP("ip6t_ROUTE: called with: ");
	DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->daddr));
	DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(*gw));
	DEBUGP("OUT=%s\n", route_info->oif);
	
	if (ipv6_addr_any(gw))
		rt = rt6_lookup(&ipv6h->daddr, &ipv6h->saddr, ifindex, 1);
	else
		rt = rt6_lookup(gw, &ipv6h->saddr, ifindex, 1);

	if (!rt)
		goto no_route;

	DEBUGP("ip6t_ROUTE: routing gives: ");
	DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_dst.addr));
	DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_gateway));
	DEBUGP("OUT=%s\n", rt->rt6i_dev->name);

	if (ifindex && rt->rt6i_dev->ifindex!=ifindex)
		goto wrong_route;
	
	if (!rt->rt6i_nexthop) {
		DEBUGP("ip6t_ROUTE: discovering neighbour\n");
		rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_dst.addr);
	}

	/* Drop old route. */
	dst_release(skb->dst);
	skb->dst = &rt->u.dst;
	skb->dev = rt->rt6i_dev;
	return 1;

 wrong_route:
	dst_release(&rt->u.dst);
 no_route:
	if (!net_ratelimit())
		return 0;

	printk("ip6t_ROUTE: no explicit route found ");
	if (ifindex)
		printk("via interface %s ", route_info->oif);
	if (!ipv6_addr_any(gw))
		printk("via gateway %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", NIP6(*gw));
	printk("\n");
	return 0;
}
Esempio n. 4
0
int mip6_mh_filter(struct sock *sk, struct sk_buff *skb)
{
	struct ip6_mh *mh;
	int mhlen;

	if (!pskb_may_pull(skb, (skb->h.raw - skb->data) + 8) ||
	    !pskb_may_pull(skb, (skb->h.raw - skb->data) + ((skb->h.raw[1] + 1) << 3)))
		return -1;

	mh = (struct ip6_mh *)skb->h.raw;

	if (mh->ip6mh_hdrlen < mip6_mh_len(mh->ip6mh_type)) {
		LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH message too short: %d vs >=%d\n",
			       mh->ip6mh_hdrlen, mip6_mh_len(mh->ip6mh_type));
		mip6_param_prob(skb, 0, (&mh->ip6mh_hdrlen) - skb->nh.raw);
		return -1;
	}
	mhlen = (mh->ip6mh_hdrlen + 1) << 3;

	if (skb->ip_summed == CHECKSUM_COMPLETE) {
		skb->ip_summed = CHECKSUM_UNNECESSARY;
		if (csum_ipv6_magic(&skb->nh.ipv6h->saddr,
				    &skb->nh.ipv6h->daddr,
				    mhlen, IPPROTO_MH,
				    skb->csum)) {
			LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH hw checksum failed\n");
			skb->ip_summed = CHECKSUM_NONE;
		}
	}
	if (skb->ip_summed == CHECKSUM_NONE) {
		if (csum_ipv6_magic(&skb->nh.ipv6h->saddr,
				    &skb->nh.ipv6h->daddr,
				    mhlen, IPPROTO_MH,
				    skb_checksum(skb, 0, mhlen, 0))) {
			LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH checksum failed "
				       "[" NIP6_FMT " > " NIP6_FMT "]\n",
				       NIP6(skb->nh.ipv6h->saddr),
				       NIP6(skb->nh.ipv6h->daddr));
			return -1;
		}
		skb->ip_summed = CHECKSUM_UNNECESSARY;
	}

	if (mh->ip6mh_proto != IPPROTO_NONE) {
		LIMIT_NETDEBUG(KERN_DEBUG "mip6: MH invalid payload proto = %d\n",
			       mh->ip6mh_proto);
		mip6_param_prob(skb, 0, (&mh->ip6mh_proto) - skb->nh.raw);
		return -1;
	}

	return 0;
}
Esempio n. 5
0
void send_request() {
  printf("new best!\n");

  char postdata[INET6_ADDRSTRLEN];
  sprintf(postdata, NIP6_FMT, NIP6(best_ip));

  CURL *curl = curl_easy_init();
  CURLcode res;

  do {
    if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) != CURLE_OK) {
      fprintf(stderr, "Error!\n");
      break;
    }

    curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
    curl_easy_setopt(curl, CURLOPT_SSLCERT, certfile);
    curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
    curl_easy_setopt(curl, CURLOPT_SSLKEY, keyfile);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);

    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postdata);

    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));

    sent = true;
    printf("Update successful.\n");
  } while(false);

  curl_easy_cleanup(curl);
}
Esempio n. 6
0
ssize_t socket_to_addrstr(struct socket *socket, char *buf)
{
	struct sockaddr uaddr;
	int uaddrlen;
	int ret;

	ret = socket->ops->getname(socket, &uaddr, &uaddrlen, 1);
	if (ret) {
		uerr("getname failed, socket %p\n", socket);
		return ret;
	}

	if (uaddr.sa_family == AF_INET) {
		struct sockaddr_in *v4addr = (struct sockaddr_in *) &uaddr;
		ret =  sprintf(buf, "%u.%u.%u.%u", NIPQUAD(v4addr->sin_addr.s_addr));
	} else if (uaddr.sa_family == AF_INET6) {
		struct sockaddr_in6 *v6addr = (struct sockaddr_in6 *) &uaddr;
		ret =  sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
				NIP6(v6addr->sin6_addr));
	} else {
		uerr("unknown sa_family %d\n", uaddr.sa_family);
		ret = -1;
	}

	return ret;
}
Esempio n. 7
0
void dump() {
  printf("\nAddresses:\n");
  for (int i = 0; i < list.size; i++) {
    struct address *addr = &list.addrs[i];
    printf("  " NIP6_FMT " ", NIP6(addr->ip));
    printf("%usec\n", addr->ifa_prefered.tv_sec);
  }
}
Esempio n. 8
0
int isert_portal_listen(struct isert_portal *portal,
			struct sockaddr *sa,
			size_t addr_len)
{
	int err;

	TRACE_ENTRY();
	err = rdma_bind_addr(portal->cm_id, sa);
	if (err) {
		pr_warn("Failed to bind rdma addr, err:%d\n", err);
		goto out;
	}
	err = rdma_listen(portal->cm_id, ISER_LISTEN_BACKLOG);
	if (err) {
		pr_err("Failed rdma listen, err:%d\n", err);
		goto out;
	}
	memcpy(&portal->addr, sa, addr_len);

	switch (sa->sa_family) {
	case AF_INET:
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
		pr_info("iser portal cm_id:%p listens on: "
			 NIPQUAD_FMT ":%d\n", portal->cm_id,
			 NIPQUAD(((struct sockaddr_in *)sa)->sin_addr.s_addr),
			(int)ntohs(((struct sockaddr_in *)sa)->sin_port));
#else
		pr_info("iser portal cm_id:%p listens on: "
			"%pI4:%d\n", portal->cm_id,
			&((struct sockaddr_in *)sa)->sin_addr.s_addr,
			(int)ntohs(((struct sockaddr_in *)sa)->sin_port));
#endif
		break;
	case AF_INET6:
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
		pr_info("iser portal cm_id:%p listens on: "
			 NIP6_FMT " %d\n",
			 portal->cm_id,
			 NIP6(((struct sockaddr_in6 *)sa)->sin6_addr),
			(int)ntohs(((struct sockaddr_in6 *)sa)->sin6_port));
#else
		pr_info("iser portal cm_id:%p listens on: "
			"%pI6 %d\n", portal->cm_id,
			&((struct sockaddr_in6 *)sa)->sin6_addr,
			(int)ntohs(((struct sockaddr_in6 *)sa)->sin6_port));
#endif
		break;
	default:
		pr_err("Unknown address family\n");
		err = -EINVAL;
		goto out;
	}

out:
	TRACE_EXIT_RES(err);
	return err;
}
Esempio n. 9
0
int ProcessDHCPIAPD(struct dhcp6_prefix  *pstPrefix, int iSet)
{
    DHCP6C_INFO_LIST stPrefix;

    if (!pstPrefix)
    {
        loginfo(FUNC, "args NULL");
        return (-1);
    }

    loginfo(FUNC, "Now, begin to process dhcp iapd ......\r\n\r\n");

    /* 增加节点 */
    if (iSet)
    {
        // TODO: 目前来说,如果一个IA带有多个前缀,那么WAN侧也只要一个前缀
        // TODO: 后续如果要支持多个前缀的话,那么需要将本函数提到update_prefix函数的上一层也就是update_ia
        if (NULL == FindNodeByType(en_type_iapd, (void *)pstPrefix))
        {
            loginfo(FUNC, "add prefix:["NIP6_FMT"]", NIP6(pstPrefix->addr));
            ClearDHCP6CInfoList(en_type_iapd);
            AddIntoList(en_type_iapd, (void *)pstPrefix);
            SetFlagByType(en_type_iapd, en_changed);
        }
    }
    else
    {
        loginfo(FUNC, "Remove iapd" NIP6_FMT " from iapd list...\r\n\r\n", NIP6(pstPrefix->addr));
        if (0 == RemoveFromList(en_type_iapd, (void *)pstPrefix))
        {
            SetFlagByType(en_type_iapd, en_changed);
        }
    }

    loginfo(FUNC, "process dhcp iapd over........\r\n\r\n\r\n");

    return (0);
}
Esempio n. 10
0
static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
                     int type, int code, int offset, __be32 info)
{
	struct ipv6hdr *iph = (struct ipv6hdr*)skb->data;
	struct ipv6_esp_hdr *esph = (struct ipv6_esp_hdr*)(skb->data+offset);
	struct xfrm_state *x;

	if (type != ICMPV6_DEST_UNREACH && 
	    type != ICMPV6_PKT_TOOBIG)
		return;

	x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET6);
	if (!x)
		return;
	printk(KERN_DEBUG "pmtu discovery on SA ESP/%08x/" NIP6_FMT "\n", 
			ntohl(esph->spi), NIP6(iph->daddr));
	xfrm_state_put(x);
}
Esempio n. 11
0
static ssize_t isert_get_initiator_ip(struct iscsi_conn *conn,
				      char *buf, int size)
{
	int pos;
	struct sockaddr_storage ss;
	size_t addr_len;

	TRACE_ENTRY();

	isert_get_peer_addr(conn, (struct sockaddr *)&ss, &addr_len);

	switch (ss.ss_family) {
	case AF_INET:
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
		pos = scnprintf(buf, size,
			 "%u.%u.%u.%u",
			 NIPQUAD(((struct sockaddr_in *)&ss)->sin_addr.s_addr));
#else
		pos = scnprintf(buf, size,
			"%pI4", &((struct sockaddr_in *)&ss)->sin_addr.s_addr);
#endif
		break;
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
	case AF_INET6:
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
		pos = scnprintf(buf, size,
			 "[%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x]",
			 NIP6(((struct sockaddr_in6 *)&ss)->sin6_addr));
#else
		pos = scnprintf(buf, size, "[%p6]",
			&((struct sockaddr_in6 *)&ss)->sin6_addr);
#endif
		break;
#endif
	default:
		pos = scnprintf(buf, size, "Unknown family %d",
			ss.ss_family);
		break;
	}

	TRACE_EXIT_RES(pos);
	return pos;
}
Esempio n. 12
0
static int ip6fl_seq_show(struct seq_file *seq, void *v)
{
	if (v == SEQ_START_TOKEN)
		seq_printf(seq, "%-5s %-1s %-6s %-6s %-6s %-8s %-32s %s\n",
			   "Label", "S", "Owner", "Users", "Linger", "Expires", "Dst", "Opt");
	else {
		struct ip6_flowlabel *fl = v;
		seq_printf(seq,
			   "%05X %-1d %-6d %-6d %-6ld %-8ld " NIP6_SEQFMT " %-4d\n",
			   (unsigned)ntohl(fl->label),
			   fl->share,
			   (unsigned)fl->owner,
			   atomic_read(&fl->users),
			   fl->linger/HZ,
			   (long)(fl->expires - jiffies)/HZ,
			   NIP6(fl->dst),
			   fl->opt ? fl->opt->opt_nflen : 0);
	}
	return 0;
}
Esempio n. 13
0
static void
dump_addr(cmdline_ipaddr_t addr)
{
	switch (addr.family) {
	case AF_INET:
	{
		printf(NIPQUAD_FMT " prefixlen=%u\n",
				NIPQUAD(addr.addr.ipv4.s_addr), addr.prefixlen);
		break;
	}
	case AF_INET6:
	{
		printf(NIP6_FMT " prefixlen=%u\n",
				NIP6(addr.addr.ipv6), addr.prefixlen);
		break;
	}
	default:
		printf("Can't dump: unknown address family.\n");
		return;
	}
}
Esempio n. 14
0
static void ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
		                int type, int code, int offset, __u32 info)
{
	u32 spi;
	struct ipv6hdr *iph = (struct ipv6hdr*)skb->data;
	struct ipv6_comp_hdr *ipcomph = (struct ipv6_comp_hdr*)(skb->data+offset);
	struct xfrm_state *x;

	if (type != ICMPV6_DEST_UNREACH || type != ICMPV6_PKT_TOOBIG)
		return;

	spi = ntohl(ntohs(ipcomph->cpi));
	x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, spi, IPPROTO_COMP, AF_INET6);
	if (!x)
		return;

	printk(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/"
			"%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
			spi, NIP6(iph->daddr));
	xfrm_state_put(x);
}
Esempio n. 15
0
static char *__svc_print_addr(struct sockaddr *addr, char *buf, size_t len)
{
	switch (addr->sa_family) {
	case AF_INET:
		snprintf(buf, len, "%u.%u.%u.%u, port=%u",
			NIPQUAD(((struct sockaddr_in *) addr)->sin_addr),
			htons(((struct sockaddr_in *) addr)->sin_port));
		break;

	case AF_INET6:
		snprintf(buf, len, "%x:%x:%x:%x:%x:%x:%x:%x, port=%u",
			NIP6(((struct sockaddr_in6 *) addr)->sin6_addr),
			htons(((struct sockaddr_in6 *) addr)->sin6_port));
		break;

	default:
		snprintf(buf, len, "unknown address type: %d", addr->sa_family);
		break;
	}
	return buf;
}
Esempio n. 16
0
static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 
                    int type, int code, int offset, __u32 info)
{
	struct ipv6hdr *iph = (struct ipv6hdr*)skb->data;
	struct ip_auth_hdr *ah = (struct ip_auth_hdr*)(skb->data+offset);
	struct xfrm_state *x;

	if (type != ICMPV6_DEST_UNREACH &&
	    type != ICMPV6_PKT_TOOBIG)
		return;

	x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET6);
	if (!x)
		return;

	NETDEBUG(printk(KERN_DEBUG "pmtu discovery on SA AH/%08x/"
			"%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
	       ntohl(ah->spi), NIP6(iph->daddr)));

	xfrm_state_put(x);
}
Esempio n. 17
0
void *FindNodeByType(INFO_TYPE_EN enType, void *pvData)
{
    DHCP6C_INFO_LIST *pstNode = NULL;

    switch(enType)
    {
    case en_type_dns:
    {
        pstNode = g_stDHCP6CUpdateInfo.pstDNSList;
        for (; pstNode; pstNode = pstNode->pstNext)
        {
            if (0 == memcmp(&pstNode->dns.stAddr, (struct in6_addr *)pvData,
                            sizeof(struct in6_addr)))
            {
                return (void *)pstNode;
            }
        }
        return (NULL);
    }
    break;
    case en_type_iapd:
    {
        struct dhcp6_prefix *pst = (struct dhcp6_prefix *)pvData;
        pstNode = g_stDHCP6CUpdateInfo.pstIAPDList;
        for (; pstNode; pstNode = pstNode->pstNext)
        {
            if (0 == ComparePrefix(pstNode->iapd.stAddr, pstNode->iapd.iPrefixLen,
                                   pst->addr, pst->plen))
            {
                return (void *)pstNode;
            }
        }
        loginfo(FUNC, "can not found:"NIP6_FMT, NIP6(pst->addr));
        return (NULL);
    }
    break;
    case en_type_iana:
    {
        struct dhcp6_statefuladdr *pst = (struct dhcp6_statefuladdr *)pvData;
        pstNode = g_stDHCP6CUpdateInfo.pstIANAList;
        for (; pstNode; pstNode = pstNode->pstNext)
        {
            if (0 == memcmp(&pstNode->iana.stAddr, &pst->addr,
                            sizeof(struct in6_addr)))
            {
                return (void *)pstNode;
            }
        }
        return (NULL);
    }
    break;
    case en_type_dslite:
    {
        pstNode = g_stDHCP6CUpdateInfo.pstDsliteList;
        for (; pstNode; pstNode = pstNode->pstNext)
        {
            if (0 == memcmp(&pstNode->dslite.stAddr, (struct in6_addr *)pvData,
                            sizeof(struct in6_addr)))
            {
                return (void *)pstNode;
            }
        }
        return (NULL);
    }
    break;
    case en_type_dslitename:
    {
        pstNode = g_stDHCP6CUpdateInfo.pstDsliteNameList;
        for (; pstNode; pstNode = pstNode->pstNext)
        {
            if (0 == strcmp(pstNode->data.stDsliteName.acDslite, (char *)pvData))
            {
                return (void *)pstNode;
            }
        }
        return (NULL);
    }
    break;
    }

    return (NULL);
}
Esempio n. 18
0
int
netsnmp_access_ipaddress_extra_prefix_info(int index, u_long *preferedlt,
                                           ulong *validlt, char *addr)
{

    struct {
            struct nlmsghdr nlhdr;
            struct ifaddrmsg ifaceinfo;
            char   buf[1024];
    } req;

    struct rtattr        *rta;
    int                  status;
    char                 buf[16384];
    char                 tmpaddr[40];
    struct nlmsghdr      *nlmp;
    struct ifaddrmsg     *rtmp;
    struct rtattr        *rtatp;
    struct ifa_cacheinfo *cache_info;
    struct in6_addr      *in6p;
    int                  rtattrlen;
    int                  sd;
    int                  reqaddr = 0;
    sd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
    if(sd < 0) {
       snmp_log(LOG_ERR, "could not open netlink socket\n");
       return -1;
    }
    memset(&req, 0, sizeof(req));
    req.nlhdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
    req.nlhdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
    req.nlhdr.nlmsg_type = RTM_GETADDR;
    req.ifaceinfo.ifa_family = AF_INET6;
    rta = (struct rtattr *)(((char *)&req) + NLMSG_ALIGN(req.nlhdr.nlmsg_len));
    rta->rta_len = RTA_LENGTH(16); /*For ipv6*/

    status = send (sd, &req, req.nlhdr.nlmsg_len, 0);
    if (status < 0) {
        snmp_log(LOG_ERR, "could not send netlink request\n");
        return -1;
    }
    status = recv (sd, buf, sizeof(buf), 0);
    if (status < 0) {
        snmp_log (LOG_ERR, "could not recieve netlink request\n");
        return -1;
    }
    if (status == 0) {
       snmp_log (LOG_ERR, "nothing to read\n");
       return -1;
    }
    for (nlmp = (struct nlmsghdr *)buf; status > sizeof(*nlmp); ){

        int len = nlmp->nlmsg_len;
        int req_len = len - sizeof(*nlmp);

        if (req_len < 0 || len > status) {
            snmp_log (LOG_ERR, "invalid netlink message\n");
            return -1;
        }

        if (!NLMSG_OK (nlmp, status)) {
            snmp_log (LOG_ERR, "invalid NLMSG message\n");
            return -1;
        }
        rtmp = (struct ifaddrmsg *)NLMSG_DATA(nlmp);
        rtatp = (struct rtattr *)IFA_RTA(rtmp);
        rtattrlen = IFA_PAYLOAD(nlmp);
        if(index == rtmp->ifa_index) {
           for (; RTA_OK(rtatp, rtattrlen); rtatp = RTA_NEXT(rtatp, rtattrlen)) {
                if(rtatp->rta_type == IFA_ADDRESS) {
                   in6p = (struct in6_addr *)RTA_DATA(rtatp);
                   sprintf(tmpaddr, "%04x%04x%04x%04x%04x%04x%04x%04x", NIP6(*in6p));
                   if(!strcmp(tmpaddr ,addr))
                       reqaddr = 1;
                }
                if(rtatp->rta_type == IFA_CACHEINFO) {
                   cache_info = (struct ifa_cacheinfo *)RTA_DATA(rtatp);
                   if(reqaddr) {
                      reqaddr = 0;
                      *validlt = cache_info->ifa_valid;
                      *preferedlt = cache_info->ifa_prefered;
                   }

                }

           }
        }
        status -= NLMSG_ALIGN(len);
        nlmp = (struct nlmsghdr*)((char*)nlmp + NLMSG_ALIGN(len));
    }
    close(sd);
    return 0;
}
Esempio n. 19
0
int
main(int argc, char *argv[])
{
        int sk, i;
        struct hostent *hst;
        sockaddr_storage_t host;
	sockaddr_storage_t msgname;
        struct iovec iov;
        struct msghdr inmessage;
	char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))];
	int error, pf_class;
	char *big_buffer;
	char *local_host = NULL;
	int local_port = SCTP_TESTPORT_1; 
        int option_index = 0;
	time_t from, to;
	int bytes_received = 0;	
        int c;
        static struct option long_options[] = {
                {"local",	1, 0, 1},
		{"local-port",	1, 0, 2},
                {0,		0, 0, 0}
        };

        /* Rather than fflush() throughout the code, set stdout to 
	 * be unbuffered. 
	 */
	setvbuf(stdout, NULL, _IONBF, 0); 

        /* Parse the arguments.  */
	while (1) {
		c = getopt_long (argc, argv, "H:P:",
                                 long_options, &option_index);
		if (c == -1)
                        break;

                switch (c) {
                case 0:
                        printf("option %s", long_options[option_index].name);
                        if (optarg) {
                                printf(" with arg %s", optarg);
                        }
                        printf("\n");
                        break;
                case 1:         /* local host */
                case 'H':
                        local_host = optarg;
                        break;
                case 2:         /* local port */
                case 'P':
                        local_port = atoi(optarg);
                        break;
                case '?':
			usage(argv[0]);
                        exit(0);

                default:
                        printf ("%s: unrecognized option 0%c\n", argv[0], c);
			usage(argv[0]);
                        exit(1);
                }
        }

        if (optind < argc)
        {
                fprintf(stderr, "%s: non-option arguments are illegal: ",
                        argv[0]);
                while (optind < argc)
                        fprintf(stderr, "%s ", argv[optind++]);
                fprintf (stderr, "\n");
		usage(argv[0]);
                exit(1);
        }

	if (!local_host) {
                fprintf(stderr, "%s: : option -H, --local is required\n",
                        argv[0]);
		usage(argv[0]);
                exit(1);
	}
	
	/* Set some basic values which depend on the address family. */
#if TEST_V6
        hst = gethostbyname2(local_host, AF_INET6);
        if (hst == NULL || hst->h_length < 1) {
                fprintf(stderr, "%s: bad hostname: %s\n", argv[0], local_host);
                exit(1);
        }
	pf_class = PF_INET6;

        host.v6.sin6_family = AF_INET6;
        memcpy(&host.v6.sin_addr, hst->h_addr_list[0], hst->h_length);
        host.v6.sin6_port = htons(local_port);

#else
	hst = gethostbyname(local_host);
        if (hst == NULL || hst->h_length < 1) {
                fprintf(stderr, "%s: bad hostname: %s\n", argv[0], local_host);
                exit(1);
        }
	pf_class = PF_INET;

        host.v4.sin_family = AF_INET;
        memcpy(&host.v4.sin_addr, hst->h_addr_list[0], hst->h_length);
        host.v4.sin_port = htons(local_port);

#endif /* TEST_V6 */

        /* Create the endpoint which will talk to nagle_snd.  */
        sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);

	/* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
	test_enable_assoc_change(sk);

        /* Bind the sockets to the test port.  */
        test_bind(sk, &host.sa, sizeof(host));
        
       /* Mark sk as being able to accept new associations.  */
	test_listen(sk, 1);
       
	printf("Listening on port:%d\n", local_port);
 
        /* Initialize inmessage for receives. */
        memset(&inmessage, 0, sizeof(inmessage));	
	big_buffer = test_malloc(REALLY_BIG);
        iov.iov_base = big_buffer;
        iov.iov_len = REALLY_BIG;
        inmessage.msg_iov = &iov;
        inmessage.msg_iovlen = 1;
        inmessage.msg_control = incmsg;
        inmessage.msg_controllen = sizeof(incmsg);
	inmessage.msg_name = &msgname;
	inmessage.msg_namelen = sizeof(msgname);
	memset(&msgname, 0, sizeof(msgname));

        /* Get the communication up message on sk.  */
        error = test_recvmsg(sk, &inmessage, MSG_WAITALL);
	test_check_msg_notification(&inmessage, error,
				    sizeof(struct sctp_assoc_change),
				    SCTP_ASSOC_CHANGE, SCTP_COMM_UP);	

	printf("Established connection with ");	
	if (AF_INET == msgname.sa.sa_family)
		printf("%d.%d.%d.%d(%d)\n", NIPQUAD(msgname.v4.sin_addr),
		       ntohs(msgname.v4.sin_port));
	if (AF_INET6 == msgname.sa.sa_family)
		printf("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x(%d)\n",
		       NIP6(msgname.v6.sin6_addr), ntohs(msgname.v6.sin6_port));

	time(&from);
	for (i=0; i<1000000; i++) {
	        inmessage.msg_controllen = sizeof(incmsg);
		inmessage.msg_namelen = sizeof(msgname);
	        error = test_recvmsg(sk, &inmessage, MSG_WAITALL);
		if (inmessage.msg_flags & MSG_NOTIFICATION)
			break;
		printf("Received %d bytes of data\n", error);
		bytes_received += error;
	}
	time(&to);

        printf("\t%d messages(%d bytes) successfully received in %ld "
	       "seconds.\n", i, bytes_received, to - from);
        printf("The receive rate is %ld bytes/second\n",
	       bytes_received/(to - from));

        /* Shut down the link.  */
	error = 0;
        close(sk);

	return 0;
}
/* One level of recursion won't kill us */
static void dump_packet(const struct ip6t_log_info *info,
			struct ipv6hdr *ipv6h, int recurse)
{
	u_int8_t currenthdr = ipv6h->nexthdr;
	u_int8_t *hdrptr;
	int fragment;

	/* Max length: 88 "SRC=0000.0000.0000.0000.0000.0000.0000.0000 DST=0000.0000.0000.0000.0000.0000.0000.0000" */
	printk("SRC=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->saddr));
	printk("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->daddr));

	/* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
	printk("LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
	       ntohs(ipv6h->payload_len) + sizeof(struct ipv6hdr),
	       (ntohl(*(u_int32_t *)ipv6h) & 0x0ff00000) >> 20,
	       ipv6h->hop_limit,
	       (ntohl(*(u_int32_t *)ipv6h) & 0x000fffff));

	fragment = 0;
	hdrptr = (u_int8_t *)(ipv6h + 1);
	while (currenthdr != IPPROTO_NONE) {
		if ((currenthdr == IPPROTO_TCP) ||
		    (currenthdr == IPPROTO_UDP) ||
		    (currenthdr == IPPROTO_ICMPV6))
			break;
		/* Max length: 48 "OPT (...) " */
		printk("OPT ( ");
		switch (currenthdr) {
		case IPPROTO_FRAGMENT: {
			struct frag_hdr *fhdr = (struct frag_hdr *)hdrptr;

			/* Max length: 11 "FRAG:65535 " */
			printk("FRAG:%u ", ntohs(fhdr->frag_off) & 0xFFF8);

			/* Max length: 11 "INCOMPLETE " */
			if (fhdr->frag_off & htons(0x0001))
				printk("INCOMPLETE ");

			printk("ID:%08x ", fhdr->identification);

			if (ntohs(fhdr->frag_off) & 0xFFF8)
				fragment = 1;

			break;
		}
		case IPPROTO_DSTOPTS:
		case IPPROTO_ROUTING:
		case IPPROTO_HOPOPTS:
			break;
		/* Max Length */
		case IPPROTO_AH:
		case IPPROTO_ESP:
			if (info->logflags & IP6T_LOG_IPOPT) {
				struct esphdr *esph = (struct esphdr *)hdrptr;
				int esp = (currenthdr == IPPROTO_ESP);

				/* Max length: 4 "ESP " */
				printk("%s ",esp ? "ESP" : "AH");

				/* Length: 15 "SPI=0xF1234567 " */
				printk("SPI=0x%x ", ntohl(esph->spi) );
				break;
			}
		default:
			break;
		}
		printk(") ");
		currenthdr = ip6_nexthdr(currenthdr, &hdrptr);
	}

	switch (currenthdr) {
	case IPPROTO_TCP: {
		struct tcphdr *tcph = (struct tcphdr *)hdrptr;

		/* Max length: 10 "PROTO=TCP " */
		printk("PROTO=TCP ");

		if (fragment)
			break;

		/* Max length: 20 "SPT=65535 DPT=65535 " */
		printk("SPT=%u DPT=%u ",
		       ntohs(tcph->source), ntohs(tcph->dest));
		/* Max length: 30 "SEQ=4294967295 ACK=4294967295 " */
		if (info->logflags & IP6T_LOG_TCPSEQ)
			printk("SEQ=%u ACK=%u ",
			       ntohl(tcph->seq), ntohl(tcph->ack_seq));
		/* Max length: 13 "WINDOW=65535 " */
		printk("WINDOW=%u ", ntohs(tcph->window));
		/* Max length: 9 "RES=0x3F " */
		printk("RES=0x%02x ", (u_int8_t)(ntohl(tcp_flag_word(tcph) & TCP_RESERVED_BITS) >> 22));
		/* Max length: 32 "CWR ECE URG ACK PSH RST SYN FIN " */
		if (tcph->cwr)
			printk("CWR ");
		if (tcph->ece)
			printk("ECE ");
		if (tcph->urg)
			printk("URG ");
		if (tcph->ack)
			printk("ACK ");
		if (tcph->psh)
			printk("PSH ");
		if (tcph->rst)
			printk("RST ");
		if (tcph->syn)
			printk("SYN ");
		if (tcph->fin)
			printk("FIN ");
		/* Max length: 11 "URGP=65535 " */
		printk("URGP=%u ", ntohs(tcph->urg_ptr));

		if ((info->logflags & IP6T_LOG_TCPOPT)
		    && tcph->doff * 4 != sizeof(struct tcphdr)) {
			unsigned int i;

			/* Max length: 127 "OPT (" 15*4*2chars ") " */
			printk("OPT (");
			for (i =sizeof(struct tcphdr); i < tcph->doff * 4; i++)
				printk("%02X", ((u_int8_t *)tcph)[i]);
			printk(") ");
		}
		break;
	}
	case IPPROTO_UDP: {
		struct udphdr *udph = (struct udphdr *)hdrptr;

		/* Max length: 10 "PROTO=UDP " */
		printk("PROTO=UDP ");

		if (fragment)
			break;

		/* Max length: 20 "SPT=65535 DPT=65535 " */
		printk("SPT=%u DPT=%u LEN=%u ",
		       ntohs(udph->source), ntohs(udph->dest),
		       ntohs(udph->len));
		break;
	}
	case IPPROTO_ICMPV6: {
		struct icmp6hdr *icmp6h = (struct icmp6hdr *)hdrptr;

		/* Max length: 13 "PROTO=ICMPv6 " */
		printk("PROTO=ICMPv6 ");

		if (fragment)
			break;

		/* Max length: 18 "TYPE=255 CODE=255 " */
		printk("TYPE=%u CODE=%u ", icmp6h->icmp6_type, icmp6h->icmp6_code);

		switch (icmp6h->icmp6_type) {
		case ICMPV6_ECHO_REQUEST:
		case ICMPV6_ECHO_REPLY:
			/* Max length: 19 "ID=65535 SEQ=65535 " */
			printk("ID=%u SEQ=%u ",
				ntohs(icmp6h->icmp6_identifier),
				ntohs(icmp6h->icmp6_sequence));
			break;
		case ICMPV6_MGM_QUERY:
		case ICMPV6_MGM_REPORT:
		case ICMPV6_MGM_REDUCTION:
			break;

		case ICMPV6_PARAMPROB:
			/* Max length: 17 "POINTER=ffffffff " */
			printk("POINTER=%08x ", ntohl(icmp6h->icmp6_pointer));
			/* Fall through */
		case ICMPV6_DEST_UNREACH:
		case ICMPV6_PKT_TOOBIG:
		case ICMPV6_TIME_EXCEED:
			/* Max length: 3+maxlen */
			if (recurse) {
				printk("[");
				dump_packet(info, (struct ipv6hdr *)(icmp6h + 1), 0);
				printk("] ");
			}

			/* Max length: 10 "MTU=65535 " */
			if (icmp6h->icmp6_type == ICMPV6_PKT_TOOBIG)
				printk("MTU=%u ", ntohl(icmp6h->icmp6_mtu));
		}
		break;
	}
	/* Max length: 10 "PROTO=255 " */
	default:
		printk("PROTO=%u ", currenthdr);
	}
}
Esempio n. 21
0
int
fillup_entry_info(netsnmp_arp_entry *entry, struct nlmsghdr *nlmp)
{
    struct ndmsg   *rtmp;
    struct in6_addr *in6p;
    struct rtattr  *tb[NDA_MAX + 1], *rta;
    size_t          in_len, out_len;
    unsigned int    i;
    int             length;
    char            addr[40];
    u_char         *buf;
    u_char         *hwaddr;

    rtmp = (struct ndmsg *) NLMSG_DATA(nlmp);
    if (nlmp->nlmsg_type != RTM_NEWNEIGH) {
        snmp_log(LOG_ERR, "Wrong netlink message type %d\n", nlmp->nlmsg_type);
        return -1;
    }

    if (rtmp->ndm_state != NUD_NOARP) {
        memset(tb, 0, sizeof(struct rtattr *) * (NDA_MAX + 1));
        length = nlmp->nlmsg_len - NLMSG_LENGTH(sizeof(*rtmp));
        if (length < 0) {
            snmp_log(LOG_ERR, "netlink message length %d < %d is invalid\n",
                     nlmp->nlmsg_len, NLMSG_LENGTH(sizeof(*rtmp)));
            return -1;
        }
        /*
         * this is what the kernel-removed NDA_RTA define did 
         */
        rta = ((struct rtattr *) (((char *) (rtmp)) +
                                  NLMSG_ALIGN(sizeof(struct ndmsg))));
        while (RTA_OK(rta, length)) {
            if (rta->rta_type <= NDA_MAX)
                tb[rta->rta_type] = rta;
            rta = RTA_NEXT(rta, length);
        }
        if (length) {
            snmp_log(LOG_ERR, "Received uneven number of netlink"
                        " messages - %d bytes remaining\n", length);
            return -1;
        }
        /*
         * Fill up the index
         */
        entry->if_index = rtmp->ndm_ifindex;
        /*
         * Fill up ip address 
         */
        if (tb[NDA_DST]) {
            memset(&addr, '\0', sizeof(addr));
            in6p = (struct in6_addr *) RTA_DATA(tb[NDA_DST]);
            sprintf(addr, NIP6_FMT, NIP6(*in6p));
            in_len = entry->arp_ipaddress_len =
                sizeof(entry->arp_ipaddress);
            netsnmp_assert(16 == in_len);
            out_len = 0;
            buf = entry->arp_ipaddress;
            if (1 != netsnmp_hex_to_binary(&buf, &in_len,
                                           &out_len, 0, addr, ":")) {
                snmp_log(LOG_ERR, "error parsing '%s', skipping\n",
                         entry->arp_ipaddress);
                return -1;
            }
            netsnmp_assert(16 == out_len);
            entry->arp_ipaddress_len = out_len;
        }
        if (tb[NDA_LLADDR]) {
            memset(&addr, '\0', sizeof(addr));
            hwaddr = RTA_DATA(tb[NDA_LLADDR]);
            entry->arp_physaddress_len = RTA_PAYLOAD(tb[NDA_LLADDR]);
            buf = entry->arp_physaddress;
            for (i = 0; i < entry->arp_physaddress_len; i++)
                entry->arp_physaddress[i] = hwaddr[i];
        }

        switch (rtmp->ndm_state) {
        case NUD_INCOMPLETE:
            entry->arp_state = INETNETTOMEDIASTATE_INCOMPLETE;
            break;
        case NUD_REACHABLE:
        case NUD_PERMANENT:
            entry->arp_state = INETNETTOMEDIASTATE_REACHABLE;
            break;
        case NUD_STALE:
            entry->arp_state = INETNETTOMEDIASTATE_STALE;
            break;
        case NUD_DELAY:
            entry->arp_state = INETNETTOMEDIASTATE_DELAY;
            break;
        case NUD_PROBE:
            entry->arp_state = INETNETTOMEDIASTATE_PROBE;
            break;
        case NUD_FAILED:
            entry->arp_state = INETNETTOMEDIASTATE_INVALID;
            break;
        case NUD_NONE:
            entry->arp_state = INETNETTOMEDIASTATE_UNKNOWN;
            break;
        default:
            snmp_log(LOG_ERR, "Unrecognized ARP entry state %d", rtmp->ndm_state);
            break;
        }

        switch (rtmp->ndm_state) {
        case NUD_INCOMPLETE:
        case NUD_FAILED:
        case NUD_NONE:
            entry->arp_type = INETNETTOMEDIATYPE_INVALID;
            break;
        case NUD_REACHABLE:
        case NUD_STALE:
        case NUD_DELAY:
        case NUD_PROBE:
            entry->arp_type = INETNETTOMEDIATYPE_DYNAMIC;
            break;
        case NUD_PERMANENT:
            entry->arp_type = INETNETTOMEDIATYPE_STATIC;
            break;
        default:
            entry->arp_type = INETNETTOMEDIATYPE_LOCAL;
            break;
        }
    } else {
        return -1;              /* could not create data for this interface */
    }

    return 0;
}
Esempio n. 22
0
static int isert_cm_conn_req_handler(struct rdma_cm_id *cm_id,
				     struct rdma_cm_event *event)
{
	/* passed in rdma_create_id */
	struct isert_portal *portal = cm_id->context;
	struct ib_device *ib_dev = cm_id->device;
	struct isert_device *isert_dev;
	struct isert_connection *isert_conn;
	struct rdma_conn_param *ini_conn_param;
	struct rdma_conn_param tgt_conn_param;
	struct isert_cm_hdr cm_hdr = { 0 };
	int err;

	TRACE_ENTRY();

	if (unlikely(!try_module_get(THIS_MODULE))) {
		err = -EINVAL;
		goto fail_get;
	}

	mutex_lock(&dev_list_mutex);
	isert_dev = isert_device_find(ib_dev);
	if (!isert_dev) {
		isert_dev = isert_device_create(ib_dev);
		if (unlikely(IS_ERR(isert_dev))) {
			err = PTR_ERR(isert_dev);
			mutex_unlock(&dev_list_mutex);
			goto fail_dev_create;
		}
	}
	isert_dev->refcnt++;
	mutex_unlock(&dev_list_mutex);

	isert_conn = isert_conn_create(cm_id, isert_dev);
	if (unlikely(IS_ERR(isert_conn))) {
		err = PTR_ERR(isert_conn);
		goto fail_conn_create;
	}

	isert_conn->state = ISER_CONN_HANDSHAKE;
	isert_conn->portal = portal;

	mutex_lock(&dev_list_mutex);
	list_add_tail(&isert_conn->portal_node, &portal->conn_list);
	mutex_unlock(&dev_list_mutex);

	/* initiator is dst, target is src */
	memcpy(&isert_conn->peer_addr, &cm_id->route.addr.dst_addr,
	       sizeof(isert_conn->peer_addr));
	memcpy(&isert_conn->self_addr, &cm_id->route.addr.src_addr,
	       sizeof(isert_conn->self_addr));

	ini_conn_param = &event->param.conn;
	memset(&tgt_conn_param, 0, sizeof(tgt_conn_param));
	tgt_conn_param.flow_control =
		ini_conn_param->flow_control;
	tgt_conn_param.rnr_retry_count =
		ini_conn_param->rnr_retry_count;

	tgt_conn_param.initiator_depth = isert_dev->device_attr.max_qp_init_rd_atom;
	if (tgt_conn_param.initiator_depth > ini_conn_param->initiator_depth)
		tgt_conn_param.initiator_depth = ini_conn_param->initiator_depth;

	tgt_conn_param.private_data_len = sizeof(cm_hdr);
	tgt_conn_param.private_data = &cm_hdr;
	cm_hdr.flags = ISER_ZBVA_NOT_SUPPORTED | ISER_SEND_W_INV_NOT_SUPPORTED;

	kref_get(&isert_conn->kref);

	err = rdma_accept(cm_id, &tgt_conn_param);
	if (unlikely(err)) {
		pr_err("Failed to accept conn request, err:%d\n", err);
		goto fail_accept;
	}

	switch (isert_conn->peer_addr.ss_family) {
	case AF_INET:
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)
		pr_info("iser accepted connection cm_id:%p "
			 NIPQUAD_FMT "->" NIPQUAD_FMT "\n", cm_id,
			 NIPQUAD(((struct sockaddr_in *)&isert_conn->peer_addr)->sin_addr.s_addr),
			 NIPQUAD(((struct sockaddr_in *)&isert_conn->self_addr)->sin_addr.s_addr));
#else
		pr_info("iser accepted connection cm_id:%p "
			"%pI4->%pI4\n", cm_id,
			&((struct sockaddr_in *)&isert_conn->peer_addr)->sin_addr.s_addr,
			&((struct sockaddr_in *)&isert_conn->self_addr)->sin_addr.s_addr);
#endif
		break;
	case AF_INET6:
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
		pr_info("iser accepted connection cm_id:%p "
			 NIP6_FMT "->" NIP6_FMT "\n", cm_id,
			 NIP6(((struct sockaddr_in6 *)&isert_conn->peer_addr)->sin6_addr),
			 NIP6(((struct sockaddr_in6 *)&isert_conn->self_addr)->sin6_addr));
#else
		pr_info("iser accepted connection cm_id:%p "
			"%pI6->%pI6\n", cm_id,
			&((struct sockaddr_in6 *)&isert_conn->peer_addr)->sin6_addr,
			&((struct sockaddr_in6 *)&isert_conn->self_addr)->sin6_addr);
#endif
		break;
	default:
		pr_info("iser accepted connection cm_id:%p\n", cm_id);
	}

out:
	TRACE_EXIT_RES(err);
	return err;

fail_accept:
	set_bit(ISERT_CONNECTION_ABORTED, &isert_conn->flags);
	isert_cm_timewait_exit_handler(cm_id, NULL);
	err = 0;
	goto out;

fail_conn_create:
	mutex_lock(&dev_list_mutex);
	isert_deref_device(isert_dev);
	mutex_unlock(&dev_list_mutex);
fail_dev_create:
	rdma_reject(cm_id, NULL, 0);
fail_get:
	module_put(THIS_MODULE);
	goto out;
}
/* get a key struct with a SPNEGO security blob, suitable for session setup */
struct key *
cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
{
	struct TCP_Server_Info *server = sesInfo->server;
	char *description, *dp;
	size_t desc_len;
	struct key *spnego_key;
	const char *hostname = server->hostname;

	/* length of fields (with semicolons): ver=0xyz ip4=ipaddress
	   host=hostname sec=mechanism uid=0xFF user=username */
	desc_len = MAX_VER_STR_LEN +
		   6 /* len of "host=" */ + strlen(hostname) +
		   5 /* len of ";ipv4=" */ + MAX_IPV6_ADDR_LEN +
		   MAX_MECH_STR_LEN +
		   7 /* len of ";uid=0x" */ + (sizeof(uid_t) * 2) +
		   6 /* len of ";user="******"ver=0x%x;host=%s;", CIFS_SPNEGO_UPCALL_VERSION,
		hostname);
	dp = description + strlen(description);

	/* add the server address */
	if (server->addr.sockAddr.sin_family == AF_INET)
		sprintf(dp, "ip4=" NIPQUAD_FMT,
			NIPQUAD(server->addr.sockAddr.sin_addr));
	else if (server->addr.sockAddr.sin_family == AF_INET6)
		sprintf(dp, "ip6=" NIP6_SEQFMT,
			NIP6(server->addr.sockAddr6.sin6_addr));
	else
		goto out;

	dp = description + strlen(description);

	/* for now, only sec=krb5 and sec=mskrb5 are valid */
	if (server->secType == Kerberos)
		sprintf(dp, ";sec=krb5");
	else if (server->secType == MSKerberos)
		sprintf(dp, ";sec=mskrb5");
	else
		goto out;

	dp = description + strlen(description);
	sprintf(dp, ";uid=0x%x", sesInfo->linux_uid);

	dp = description + strlen(description);
	sprintf(dp, ";user=%s", sesInfo->userName);

	cFYI(1, ("key description = %s", description));
	spnego_key = request_key(&cifs_spnego_key_type, description, "");

#ifdef CONFIG_CIFS_DEBUG2
	if (cifsFYI && !IS_ERR(spnego_key)) {
		struct cifs_spnego_msg *msg = spnego_key->payload.data;
		cifs_dump_mem("SPNEGO reply blob:", msg->data, min(1024U,
				msg->secblob_len + msg->sesskey_len));
	}
#endif /* CONFIG_CIFS_DEBUG2 */

out:
	kfree(description);
	return spnego_key;
}
Esempio n. 24
0
/* One level of recursion won't kill us */
static void dump_packet(const struct nf_loginfo *info,
            const struct sk_buff *skb, unsigned int ip6hoff,
            int recurse)
{
    u_int8_t currenthdr;
    int fragment;
    struct ipv6hdr _ip6h;
    const struct ipv6hdr *ih;
    unsigned int ptr;
    unsigned int hdrlen = 0;
    unsigned int logflags;

    if (info->type == NF_LOG_TYPE_LOG)
        logflags = info->u.log.logflags;
    else
        logflags = NF_LOG_MASK;

    ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h);
    if (ih == NULL) {
        printk("TRUNCATED");
        return;
    }

    /* Max length: 88 "SRC=0000.0000.0000.0000.0000.0000.0000.0000 DST=0000.0000.0000.0000.0000.0000.0000.0000 " */
    printk("SRC=" NIP6_FMT " DST=" NIP6_FMT " ", NIP6(ih->saddr), NIP6(ih->daddr));

    /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
    printk("LEN=%Zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
           ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
           (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
           ih->hop_limit,
           (ntohl(*(__be32 *)ih) & 0x000fffff));

    fragment = 0;
    ptr = ip6hoff + sizeof(struct ipv6hdr);
    currenthdr = ih->nexthdr;
    while (currenthdr != NEXTHDR_NONE && ip6t_ext_hdr(currenthdr)) {
        struct ipv6_opt_hdr _hdr;
        const struct ipv6_opt_hdr *hp;

        hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr);
        if (hp == NULL) {
            printk("TRUNCATED");
            return;
        }

        /* Max length: 48 "OPT (...) " */
        if (logflags & IP6T_LOG_IPOPT)
            printk("OPT ( ");

        switch (currenthdr) {
        case IPPROTO_FRAGMENT: {
            struct frag_hdr _fhdr;
            const struct frag_hdr *fh;

            printk("FRAG:");
            fh = skb_header_pointer(skb, ptr, sizeof(_fhdr),
                        &_fhdr);
            if (fh == NULL) {
                printk("TRUNCATED ");
                return;
            }

            /* Max length: 6 "65535 " */
            printk("%u ", ntohs(fh->frag_off) & 0xFFF8);

            /* Max length: 11 "INCOMPLETE " */
            if (fh->frag_off & htons(0x0001))
                printk("INCOMPLETE ");

            printk("ID:%08x ", ntohl(fh->identification));

            if (ntohs(fh->frag_off) & 0xFFF8)
                fragment = 1;

            hdrlen = 8;

            break;
        }
        case IPPROTO_DSTOPTS:
        case IPPROTO_ROUTING:
        case IPPROTO_HOPOPTS:
            if (fragment) {
                if (logflags & IP6T_LOG_IPOPT)
                    printk(")");
                return;
            }
            hdrlen = ipv6_optlen(hp);
            break;
        /* Max Length */
        case IPPROTO_AH:
            if (logflags & IP6T_LOG_IPOPT) {
                struct ip_auth_hdr _ahdr;
                const struct ip_auth_hdr *ah;

                /* Max length: 3 "AH " */
                printk("AH ");

                if (fragment) {
                    printk(")");
                    return;
                }

                ah = skb_header_pointer(skb, ptr, sizeof(_ahdr),
                            &_ahdr);
                if (ah == NULL) {
                    /*
                     * Max length: 26 "INCOMPLETE [65535
                     *  bytes] )"
                     */
                    printk("INCOMPLETE [%u bytes] )",
                           skb->len - ptr);
                    return;
                }

                /* Length: 15 "SPI=0xF1234567 */
                printk("SPI=0x%x ", ntohl(ah->spi));

            }

            hdrlen = (hp->hdrlen+2)<<2;
            break;
        case IPPROTO_ESP:
            if (logflags & IP6T_LOG_IPOPT) {
                struct ip_esp_hdr _esph;
                const struct ip_esp_hdr *eh;

                /* Max length: 4 "ESP " */
                printk("ESP ");

                if (fragment) {
                    printk(")");
                    return;
                }

                /*
                 * Max length: 26 "INCOMPLETE [65535 bytes] )"
                 */
                eh = skb_header_pointer(skb, ptr, sizeof(_esph),
                            &_esph);
                if (eh == NULL) {
                    printk("INCOMPLETE [%u bytes] )",
                           skb->len - ptr);
                    return;
                }

                /* Length: 16 "SPI=0xF1234567 )" */
                printk("SPI=0x%x )", ntohl(eh->spi) );

            }
            return;
        default:
            /* Max length: 20 "Unknown Ext Hdr 255" */
            printk("Unknown Ext Hdr %u", currenthdr);
            return;
        }
        if (logflags & IP6T_LOG_IPOPT)
            printk(") ");

        currenthdr = hp->nexthdr;
        ptr += hdrlen;
    }

    switch (currenthdr) {
    case IPPROTO_TCP: {
        struct tcphdr _tcph;
        const struct tcphdr *th;

        /* Max length: 10 "PROTO=TCP " */
        printk("PROTO=TCP ");

        if (fragment)
            break;

        /* Max length: 25 "INCOMPLETE [65535 bytes] " */
        th = skb_header_pointer(skb, ptr, sizeof(_tcph), &_tcph);
        if (th == NULL) {
            printk("INCOMPLETE [%u bytes] ", skb->len - ptr);
            return;
        }

        /* Max length: 20 "SPT=65535 DPT=65535 " */
        printk("SPT=%u DPT=%u ",
               ntohs(th->source), ntohs(th->dest));
        /* Max length: 30 "SEQ=4294967295 ACK=4294967295 " */
        if (logflags & IP6T_LOG_TCPSEQ)
            printk("SEQ=%u ACK=%u ",
                   ntohl(th->seq), ntohl(th->ack_seq));
        /* Max length: 13 "WINDOW=65535 " */
        printk("WINDOW=%u ", ntohs(th->window));
        /* Max length: 9 "RES=0x3C " */
        printk("RES=0x%02x ", (u_int8_t)(ntohl(tcp_flag_word(th) & TCP_RESERVED_BITS) >> 22));
        /* Max length: 32 "CWR ECE URG ACK PSH RST SYN FIN " */
        if (th->cwr)
            printk("CWR ");
        if (th->ece)
            printk("ECE ");
        if (th->urg)
            printk("URG ");
        if (th->ack)
            printk("ACK ");
        if (th->psh)
            printk("PSH ");
        if (th->rst)
            printk("RST ");
        if (th->syn)
            printk("SYN ");
        if (th->fin)
            printk("FIN ");
        /* Max length: 11 "URGP=65535 " */
        printk("URGP=%u ", ntohs(th->urg_ptr));

        if ((logflags & IP6T_LOG_TCPOPT)
            && th->doff * 4 > sizeof(struct tcphdr)) {
            u_int8_t _opt[60 - sizeof(struct tcphdr)];
            const u_int8_t *op;
            unsigned int i;
            unsigned int optsize = th->doff * 4
                           - sizeof(struct tcphdr);

            op = skb_header_pointer(skb,
                        ptr + sizeof(struct tcphdr),
                        optsize, _opt);
            if (op == NULL) {
                printk("OPT (TRUNCATED)");
                return;
            }

            /* Max length: 127 "OPT (" 15*4*2chars ") " */
            printk("OPT (");
            for (i =0; i < optsize; i++)
                printk("%02X", op[i]);
            printk(") ");
        }
        break;
    }
    case IPPROTO_UDP:
    case IPPROTO_UDPLITE: {
        struct udphdr _udph;
        const struct udphdr *uh;

        if (currenthdr == IPPROTO_UDP)
            /* Max length: 10 "PROTO=UDP "     */
            printk("PROTO=UDP " );
        else    /* Max length: 14 "PROTO=UDPLITE " */
            printk("PROTO=UDPLITE ");

        if (fragment)
            break;

        /* Max length: 25 "INCOMPLETE [65535 bytes] " */
        uh = skb_header_pointer(skb, ptr, sizeof(_udph), &_udph);
        if (uh == NULL) {
            printk("INCOMPLETE [%u bytes] ", skb->len - ptr);
            return;
        }

        /* Max length: 20 "SPT=65535 DPT=65535 " */
        printk("SPT=%u DPT=%u LEN=%u ",
               ntohs(uh->source), ntohs(uh->dest),
               ntohs(uh->len));
        break;
    }
    case IPPROTO_ICMPV6: {
        struct icmp6hdr _icmp6h;
        const struct icmp6hdr *ic;

        /* Max length: 13 "PROTO=ICMPv6 " */
        printk("PROTO=ICMPv6 ");

        if (fragment)
            break;

        /* Max length: 25 "INCOMPLETE [65535 bytes] " */
        ic = skb_header_pointer(skb, ptr, sizeof(_icmp6h), &_icmp6h);
        if (ic == NULL) {
            printk("INCOMPLETE [%u bytes] ", skb->len - ptr);
            return;
        }

        /* Max length: 18 "TYPE=255 CODE=255 " */
        printk("TYPE=%u CODE=%u ", ic->icmp6_type, ic->icmp6_code);

        switch (ic->icmp6_type) {
        case ICMPV6_ECHO_REQUEST:
        case ICMPV6_ECHO_REPLY:
            /* Max length: 19 "ID=65535 SEQ=65535 " */
            printk("ID=%u SEQ=%u ",
                ntohs(ic->icmp6_identifier),
                ntohs(ic->icmp6_sequence));
            break;
        case ICMPV6_MGM_QUERY:
        case ICMPV6_MGM_REPORT:
        case ICMPV6_MGM_REDUCTION:
            break;

        case ICMPV6_PARAMPROB:
            /* Max length: 17 "POINTER=ffffffff " */
            printk("POINTER=%08x ", ntohl(ic->icmp6_pointer));
            /* Fall through */
        case ICMPV6_DEST_UNREACH:
        case ICMPV6_PKT_TOOBIG:
        case ICMPV6_TIME_EXCEED:
            /* Max length: 3+maxlen */
            if (recurse) {
                printk("[");
                dump_packet(info, skb, ptr + sizeof(_icmp6h),
                        0);
                printk("] ");
            }

            /* Max length: 10 "MTU=65535 " */
            if (ic->icmp6_type == ICMPV6_PKT_TOOBIG)
                printk("MTU=%u ", ntohl(ic->icmp6_mtu));
        }
        break;
    }
    /* Max length: 10 "PROTO=255 " */
    default:
        printk("PROTO=%u ", currenthdr);
    }

    /* Max length: 15 "UID=4294967295 " */
    if ((logflags & IP6T_LOG_UID) && recurse && skb->sk) {
        read_lock_bh(&skb->sk->sk_callback_lock);
        if (skb->sk->sk_socket && skb->sk->sk_socket->file)
            printk("UID=%u GID=%u ",
                skb->sk->sk_socket->file->f_uid,
                skb->sk->sk_socket->file->f_gid);
        read_unlock_bh(&skb->sk->sk_callback_lock);
    }

    /* Max length: 16 "MARK=0xFFFFFFFF " */
    if (!recurse && skb->mark)
        printk("MARK=0x%x ", skb->mark);
}
Esempio n. 25
0
static void
ebt_log_packet(unsigned int pf, unsigned int hooknum,
   const struct sk_buff *skb, const struct net_device *in,
   const struct net_device *out, const struct nf_loginfo *loginfo,
   const char *prefix)
{
	unsigned int bitmask;

	spin_lock_bh(&ebt_log_lock);
	printk("<%c>%s IN=%s OUT=%s MAC source = ", '0' + loginfo->u.log.level,
	       prefix, in ? in->name : "", out ? out->name : "");

	print_MAC(eth_hdr(skb)->h_source);
	printk("MAC dest = ");
	print_MAC(eth_hdr(skb)->h_dest);

	printk("proto = 0x%04x", ntohs(eth_hdr(skb)->h_proto));

	if (loginfo->type == NF_LOG_TYPE_LOG)
		bitmask = loginfo->u.log.logflags;
	else
		bitmask = NF_LOG_MASK;

	if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto ==
	   htons(ETH_P_IP)){
		const struct iphdr *ih;
		struct iphdr _iph;

		ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
		if (ih == NULL) {
			printk(" INCOMPLETE IP header");
			goto out;
		}
		printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u, IP "
		       "tos=0x%02X, IP proto=%d", NIPQUAD(ih->saddr),
		       NIPQUAD(ih->daddr), ih->tos, ih->protocol);
		print_ports(skb, ih->protocol, ih->ihl*4);
		goto out;
	}

#if defined(CONFIG_BRIDGE_EBT_IP6) || defined(CONFIG_BRIDGE_EBT_IP6_MODULE)
	if ((bitmask & EBT_LOG_IP6) && eth_hdr(skb)->h_proto ==
	   htons(ETH_P_IPV6)) {
		const struct ipv6hdr *ih;
		struct ipv6hdr _iph;
		uint8_t nexthdr;
		int offset_ph;

		ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
		if (ih == NULL) {
			printk(" INCOMPLETE IPv6 header");
			goto out;
		}
		printk(" IPv6 SRC=%x:%x:%x:%x:%x:%x:%x:%x "
		       "IPv6 DST=%x:%x:%x:%x:%x:%x:%x:%x, IPv6 "
		       "priority=0x%01X, Next Header=%d", NIP6(ih->saddr),
		       NIP6(ih->daddr), ih->priority, ih->nexthdr);
		nexthdr = ih->nexthdr;
		offset_ph = ipv6_skip_exthdr(skb, sizeof(_iph), &nexthdr);
		if (offset_ph == -1)
			goto out;
		print_ports(skb, nexthdr, offset_ph);
		goto out;
	}
#endif

	if ((bitmask & EBT_LOG_ARP) &&
	    ((eth_hdr(skb)->h_proto == htons(ETH_P_ARP)) ||
	     (eth_hdr(skb)->h_proto == htons(ETH_P_RARP)))) {
		const struct arphdr *ah;
		struct arphdr _arph;

		ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
		if (ah == NULL) {
			printk(" INCOMPLETE ARP header");
			goto out;
		}
		printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
		       ntohs(ah->ar_hrd), ntohs(ah->ar_pro),
		       ntohs(ah->ar_op));

		/* If it's for Ethernet and the lengths are OK,
		 * then log the ARP payload */
		if (ah->ar_hrd == htons(1) &&
		    ah->ar_hln == ETH_ALEN &&
		    ah->ar_pln == sizeof(__be32)) {
			const struct arppayload *ap;
			struct arppayload _arpp;

			ap = skb_header_pointer(skb, sizeof(_arph),
						sizeof(_arpp), &_arpp);
			if (ap == NULL) {
				printk(" INCOMPLETE ARP payload");
				goto out;
			}
			printk(" ARP MAC SRC=");
			print_MAC(ap->mac_src);
			printk(" ARP IP SRC=%u.%u.%u.%u",
			       myNIPQUAD(ap->ip_src));
			printk(" ARP MAC DST=");
			print_MAC(ap->mac_dst);
			printk(" ARP IP DST=%u.%u.%u.%u",
			       myNIPQUAD(ap->ip_dst));
		}
	}
out:
	printk("\n");
	spin_unlock_bh(&ebt_log_lock);

}
Esempio n. 26
0
int RemoveFromList(INFO_TYPE_EN enType, void *pvData)
{
    DHCP6C_INFO_LIST *pstCur = NULL;
    DHCP6C_INFO_LIST *pstPrev = NULL;

    if (!pvData)
    {
        fprintf(stderr, "args NULL......");
        return (-1);
    }

    switch(enType)
    {
    case en_type_dns:       /* 待实现 */
        return (-1);
    case en_type_iapd:
    {
        struct dhcp6_prefix  *pstPrefix = (struct dhcp6_prefix *)pvData;
        pstCur = FindNodeByType(en_type_dns, pstPrefix);
        if (NULL == pstCur)
        {
            loginfo(FUNC, "can not found the iapd for"NIP6_FMT,  NIP6(pstPrefix->addr));
            return (-1);
        }

        loginfo(FUNC, "found the node... so begin to delete the iapd......\r\n\r\n\r\n");

        /* 头结点 */
        if (pstCur == g_stDHCP6CUpdateInfo.pstIAPDList)
        {
            loginfo(FUNC, "head node........\r\n\r\n\r\n");
            g_stDHCP6CUpdateInfo.pstIAPDList = g_stDHCP6CUpdateInfo.pstIAPDList->pstNext;
            g_stDHCP6CUpdateInfo.iNewPrefixNum -= 1;
            free(pstCur);
        }
        else
        {
            pstCur = g_stDHCP6CUpdateInfo.pstIAPDList;
            for (; pstCur; pstCur = pstCur->pstNext)
            {
                if (0 == ComparePrefix(pstCur->iapd.stAddr, pstCur->iapd.iPrefixLen,
                                       pstPrefix->addr, pstPrefix->plen))
                {
                    if (NULL != pstPrev)
                    {
                        pstPrev->pstNext = pstCur->pstNext;
                        g_stDHCP6CUpdateInfo.iNewPrefixNum -= 1;
                        free(pstCur);
                        break;
                    }
                }
                pstPrev = pstCur;
            }
        }
        loginfo(FUNC, "Remove iapd from list over.....\r\n\r\n");
        //SetFlagByType(en_type_iapd,en_changed);
        return (0);
    }
    break;
    case en_type_iana:      /* 待实现 */
        return (-1);
    case en_type_dslite:      /* 待实现 */
        return (-1);
    case en_type_dslitename:      /* 待实现 */
        return (-1);
    default:
        return (-1);
    }
}