static int 
_load_udp_endpoint_table_v6(netsnmp_container *container, int flag) 
{
    netsnmp_udp_endpoint_entry *ep;
    mib2_udp6Entry_t ue6;
    req_e            req = GET_FIRST;

    DEBUGMSGT(("access:udp_endpoint:container", "load v6\n"));

    while (getMibstat(MIB_UDP6_ENDPOINT, &ue6, sizeof(ue6), req, 
                      &Get_everything, 0)==0) {
        req = GET_NEXT;
        ep = netsnmp_access_udp_endpoint_entry_create();
        if (ep == NULL)
            return (-1);
        DEBUGMSGT(("access:udp_endpoint:container", "add entry\n"));

        /* 
         * local address/port. 
         */
        ep->loc_addr_len = sizeof(ue6.udp6LocalAddress);
        if (sizeof(ep->loc_addr) < ep->loc_addr_len) {
            netsnmp_access_udp_endpoint_entry_free(ep);
            return (-1);
        }
        (void)memcpy(&ep->loc_addr, &ue6.udp6LocalAddress, ep->loc_addr_len);

        ep->loc_port = ue6.udp6LocalPort;

        /* remote address/port */
        if (IN6_IS_ADDR_UNSPECIFIED(&ue6.udp6EntryInfo.ue_RemoteAddress)) {
            ep->rmt_addr_len = 0;
        } else {
            ep->rmt_addr_len = sizeof(ue6.udp6EntryInfo.ue_RemoteAddress);
            (void)memcpy(&ep->rmt_addr, &ue6.udp6EntryInfo.ue_RemoteAddress,
                         ep->rmt_addr_len);
        }
        ep->rmt_port = ue6.udp6EntryInfo.ue_RemotePort;

        /* instance */
#ifdef SOLARIS_HAVE_RFC4293_SUPPORT  
        ep->instance = ue6.udp6Instance; 
#else
        ep->instance = 0;
#endif
        /* state */
        ep->state = 0; 

        /* index */
        ep->index = CONTAINER_SIZE(container) + 1;        
        ep->oid_index.oids = &ep->index;
        ep->oid_index.len = 1;

        CONTAINER_INSERT(container, (void *)ep);
    }
    return (0);
}
Beispiel #2
0
/**
 *
 * @retval  0 no errors
 * @retval !0 errors
 */
static int
_kvmload(netsnmp_container *container, u_int load_flags)
{
    netsnmp_udp_endpoint_entry  *entry;
    struct   kinfo_file *kf;
    int      count;
    int      rc = 0;

    kf = kvm_getfiles(kd, KERN_FILE_BYFILE, DTYPE_SOCKET, sizeof(struct kinfo_file), &count);

    while (count--) {
	if (kf->so_protocol != IPPROTO_UDP)
	    goto skip;
#if !defined(NETSNMP_ENABLE_IPV6)
        if (kf->so_family == AF_INET6)
	    goto skip;
#endif

        entry = netsnmp_access_udp_endpoint_entry_create();
        if(NULL == entry) {
            rc = -3;
            break;
        }

        /** oddly enough, these appear to already be in network order */
        entry->loc_port = ntohs(kf->inp_lport);
        entry->rmt_port = ntohs(kf->inp_fport);
        entry->pid = kf->p_pid;
        
        /** the addr string may need work */
	if (kf->so_family == AF_INET6) {
	    entry->loc_addr_len = entry->rmt_addr_len = 16;
	    memcpy(entry->loc_addr, &kf->inp_laddru, 16);
	    memcpy(entry->rmt_addr, &kf->inp_faddru, 16);
	}
	else {
	    entry->loc_addr_len = entry->rmt_addr_len = 4;
	    memcpy(entry->loc_addr, &kf->inp_laddru[0], 4);
	    memcpy(entry->rmt_addr, &kf->inp_faddru[0], 4);
	}
	DEBUGMSGTL(("udp-mib/data_access", "udp %d %d %d\n",
	    entry->loc_addr_len, entry->loc_port, entry->rmt_port));

        /*
         * add entry to container
         */
        entry->index = CONTAINER_SIZE(container) + 1;
        CONTAINER_INSERT(container, entry);
skip:
	kf++;
    }

    if (rc < 0)
    return rc;
    return 0;
}
/**
 *
 * @retval  0 no errors
 * @retval !0 errors
 */
static int
_load(netsnmp_container *container, u_int load_flags)
{
    size_t   len;
    int      sname[] = { CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_PCBLIST };
    char     *udpcb_buf = NULL;
#if defined(dragonfly)
    struct xinpcb  *xig = NULL;
#else
    struct xinpgen *xig = NULL;
#endif
    netsnmp_udp_endpoint_entry  *entry;
    int      rc = 0;

    /*
     *  Read in the buffer containing the TCP table data
     */
    len = 0;
    if (sysctl(sname, 4, 0, &len, 0, 0) < 0 ||
       (udpcb_buf = malloc(len)) == NULL)
        return -1;
    if (sysctl(sname, 4, udpcb_buf, &len, 0, 0) < 0) {
        free(udpcb_buf);
        return -1;
    }

    /*
     *  Unpick this into the constituent 'xinpgen' structures, and extract
     *     the 'inpcb' elements into a linked list (built in reverse)
     */
#if defined(dragonfly)
    xig = (struct xinpcb  *) udpcb_buf;
#else
    xig = (struct xinpgen *) udpcb_buf;
    xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
#endif

#if defined(dragonfly)
    while (xig && (xig->xi_len >= sizeof(struct xinpcb)))
#else
    while (xig && (xig->xig_len > sizeof(struct xinpgen)))
#endif
    {
	NS_ELEM pcb = *((NS_ELEM *) xig);
#if defined(dragonfly)
	xig = (struct xinpcb  *) ((char *) xig + xig->xi_len);
#else
	xig = (struct xinpgen *) ((char *) xig + xig->xig_len);
#endif

#if !defined(NETSNMP_ENABLE_IPV6)
#ifdef INP_ISIPV6
        if (INP_ISIPV6(&pcb.xi_inp))
#else
        if (pcb.xi_inp.inp_vflag & INP_IPV6)
#endif
	    continue;
#endif

        entry = netsnmp_access_udp_endpoint_entry_create();
        if(NULL == entry) {
            rc = -3;
            break;
        }

        /** oddly enough, these appear to already be in network order */
        entry->loc_port = htons(pcb.xi_inp.inp_lport);
        entry->rmt_port = htons(pcb.xi_inp.inp_fport);
        entry->pid = 0;
        
        /** the addr string may need work */
#ifdef INP_ISIPV6
	if (INP_ISIPV6(&pcb.xi_inp)) {
#else
	if (pcb.xi_inp.inp_vflag & INP_IPV6) {
#endif
	    entry->loc_addr_len = entry->rmt_addr_len = 16;
	    memcpy(entry->loc_addr, &pcb.xi_inp.in6p_laddr, 16);
	    memcpy(entry->rmt_addr, &pcb.xi_inp.in6p_faddr, 16);
	}
	else {
	    entry->loc_addr_len = entry->rmt_addr_len = 4;
	    memcpy(entry->loc_addr, &pcb.xi_inp.inp_laddr, 4);
	    memcpy(entry->rmt_addr, &pcb.xi_inp.inp_faddr, 4);
	}

        /*
         * add entry to container
         */
	entry->index = CONTAINER_SIZE(container) + 1;
        CONTAINER_INSERT(container, entry);
    }

    free(udpcb_buf);

    if(rc<0)
        return rc;

    return 0;
}
Beispiel #4
0
/**
 *
 * @retval  0 no errors
 * @retval !0 errors
 */
static int
_load(netsnmp_container *container, u_int load_flags)
{
    struct inpcbtable table;
    struct inpcb   *head, *next, *prev;
    struct inpcb   inpcb;
    netsnmp_udp_endpoint_entry  *entry;
    int      rc = 0;

    /*
     *  Read in the buffer containing the TCP table data
     */
    if (!auto_nlist(UDB_SYMBOL, (char *) &table, sizeof(table))) {
	DEBUGMSGTL(("udp-mib/udp_endpoint_openbsd", "Failed to read udp_symbol\n"));
	return -1;
    }

    prev = (struct inpcb *)&CIRCLEQ_FIRST(&table.inpt_queue);
    prev = NULL;
    head = next = CIRCLEQ_FIRST(&table.inpt_queue);

    while (next) {
	NETSNMP_KLOOKUP(next, (char *)&inpcb, sizeof(inpcb));
	if (prev && CIRCLEQ_PREV(&inpcb, inp_queue) != prev) {
	    snmp_log(LOG_ERR,"udbtable link error\n");
	    break;
	}
	prev = next;
	next = CIRCLEQ_NEXT(&inpcb, inp_queue);

#if !defined(NETSNMP_ENABLE_IPV6)
        if (inpcb.inp_flags & INP_IPV6)
            goto skip;
#endif
        entry = netsnmp_access_udp_endpoint_entry_create();
        if (NULL == entry) {
            rc = -3;
            break;
        }

        /** oddly enough, these appear to already be in network order */
        entry->loc_port = ntohs(inpcb.inp_lport);
        entry->rmt_port = ntohs(inpcb.inp_fport);
        entry->pid = 0;
        
        /** the addr string may need work */
	if (inpcb.inp_flags & INP_IPV6) {
	    entry->loc_addr_len = entry->rmt_addr_len = 16;
	    memcpy(entry->loc_addr, &inpcb.inp_laddr6, 16);
	    memcpy(entry->rmt_addr, &inpcb.inp_faddr6, 16);
	}
	else {
	    entry->loc_addr_len = entry->rmt_addr_len = 4;
	    memcpy(entry->loc_addr, &inpcb.inp_laddr, 4);
	    memcpy(entry->rmt_addr, &inpcb.inp_faddr, 4);
	}

        /*
         * add entry to container
         */
        entry->index = CONTAINER_SIZE(container) + 1;
        CONTAINER_INSERT(container, entry);
#if !defined(NETSNMP_ENABLE_IPV6)
    skip:
#endif
	if (next == head)
	    break;
    }

    if (rc < 0)
        return rc;

    return 0;
}
static int 
_load_udp_endpoint_table_v4(netsnmp_container *container, int flag) 
{
    netsnmp_udp_endpoint_entry *ep;
    mib2_udpEntry_t ue;
    req_e           req = GET_FIRST;

    DEBUGMSGT(("access:udp_endpoint:container", "load v4\n"));

    while (getMibstat(MIB_UDP_LISTEN, &ue, sizeof(ue), req, 
                          &Get_everything, 0)==0) {
        req = GET_NEXT;
        ep = netsnmp_access_udp_endpoint_entry_create();
        if (ep == NULL)
            return (-1);
        DEBUGMSGT(("access:udp_endpoint:container", "add entry\n"));

        /* 
         * local address/port. 
         */
        ep->loc_addr_len = sizeof(ue.udpLocalAddress);
        if (sizeof(ep->loc_addr) < ep->loc_addr_len) {
            netsnmp_access_udp_endpoint_entry_free(ep);
            return (-1);
        }
        memcpy(&ep->loc_addr, &ue.udpLocalAddress, ep->loc_addr_len);

        ep->loc_port = ue.udpLocalPort;

        /* 
         * remote address/port. The address length is the same as the
         * local address, so no check needed. If the remote address is
         * unspecfied, then the type should be set to "unknown" (per RFC 4113).
         */
        if (ue.udpEntryInfo.ue_RemoteAddress == INADDR_ANY) {
            ep->rmt_addr_len = 0;
        } else { 
            ep->rmt_addr_len = sizeof(ue.udpEntryInfo.ue_RemoteAddress);
            memcpy(&ep->rmt_addr, &ue.udpEntryInfo.ue_RemoteAddress, 
                   ep->rmt_addr_len);
        }

        ep->rmt_port = ue.udpEntryInfo.ue_RemotePort;

        /* 
         * instance - if there is support for RFC 4293, then we also have
         * support for RFC 4113.
         */
#ifdef SOLARIS_HAVE_RFC4293_SUPPORT 
        ep->instance = ue.udpInstance; 
#else
        ep->instance = 0;
#endif
        
        /* state */
        ep->state = 0; 

        /* index */
        ep->index = CONTAINER_SIZE(container) + 1;        
        ep->oid_index.oids = &ep->index;
        ep->oid_index.len = 1; 

        CONTAINER_INSERT(container, (void *)ep);
    }
    return (0);
}