コード例 #1
0
static int
onlp_snmp_sensor_register_oid__(onlp_oid_t oid, void* cookie)
{
    onlp_oid_hdr_t hdr;
    onlp_snmp_sensor_t s;

    onlp_oid_hdr_get(oid, &hdr);

    AIM_MEMSET(&s, 0x0, sizeof(onlp_snmp_sensor_t));
    switch(ONLP_OID_TYPE_GET(oid))
        {
        case ONLP_OID_TYPE_THERMAL:
#if ONLP_SNMP_CONFIG_INCLUDE_THERMALS == 1
            s.sensor_id = oid;
            sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid));
            aim_strlcpy(s.desc, hdr.description, sizeof(s.desc));
            if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_TEMP, &s) < 0) {
                AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid);
            }
#endif
            break;

        case ONLP_OID_TYPE_FAN:
#if ONLP_SNMP_CONFIG_INCLUDE_FANS == 1
            s.sensor_id = oid;
            sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid));
            aim_strlcpy(s.desc, hdr.description, sizeof(s.desc));
            if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_FAN, &s) < 0) {
                AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid);
            }
#endif
            break;

        case ONLP_OID_TYPE_PSU:
#if ONLP_SNMP_CONFIG_INCLUDE_PSUS == 1
            /* Register Sensors for VIN,VOUT,IIN,IOUT,PIN,POUT */
            s.sensor_id = oid;
            sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid));
            aim_strlcpy(s.desc, hdr.description, sizeof(s.desc));
            if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_PSU, &s) < 0) {
                AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid);
            }
#endif
            break;

        default:
            AIM_LOG_INFO("snmp type %s id %d unsupported",
                         onlp_oid_type_name(ONLP_OID_TYPE_GET(oid)),
                         ONLP_OID_ID_GET(oid));
            break;
    }

    return 0;
}
コード例 #2
0
int
vpi_mmap_interface_create(vpi_interface_t** vi, char* args[], int flags,
                       const char* vpi_name_ptr)
{
    struct sockaddr_ll sockaddr;
    struct packet_mreq sockparams;
    struct tpacket_req treq;
    struct ifreq ifreq;
    vpi_interface_mmap_t* nvi = aim_zmalloc(sizeof(*nvi));
    char** arg = args;
    int version;
    int i;
    frame_control_t* fc;

    AIM_REFERENCE(flags);

    if(nvi == NULL) {
        VPI_MERROR("interface allocation failed for %s.",
                   vpi_name_ptr);
        return -1;
    }

    /*
     * Point our log_string to our name so we can use it immediately
     * in log messages.
     */
    nvi->log_string = vpi_name_ptr;


    /*
     * The first argument is the type -- skip for now
     */
    arg++;

    aim_strlcpy(nvi->interface_name, *arg, sizeof(nvi->interface_name));

    /* Create RAW socket */
    if((nvi->fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
        VPI_ERROR(nvi, "socket() failed: %s\n", strerror(errno));
        aim_free(nvi);
        return -1;
    }

    /* Set version */
    version = TPACKET_V2;
    if(setsockopt(nvi->fd, SOL_PACKET, PACKET_VERSION,
                  &version, sizeof(version)) < 0) {
        VPI_ERROR(nvi, "setsockopt() version failed: %s\n", strerror(errno));
        aim_free(nvi);
        return -1;
    }

    /*
     * Get the interface index for the requested interface, as specified
     * in the current argument.
     */
    VPI_MEMSET(&ifreq, 0, sizeof(ifreq));
    aim_strlcpy(ifreq.ifr_name, nvi->interface_name, IFNAMSIZ);
    if(ioctl(nvi->fd, SIOCGIFINDEX, &ifreq) < 0) {
        VPI_ERROR(nvi, "ioctl() failed: %s", strerror(errno));
        close(nvi->fd);
        aim_free(nvi);
        return -1;
    }
    nvi->ifindex = ifreq.ifr_ifindex;
    VPI_INFO(nvi, "ifndex is %d", nvi->ifindex);

    /* Set promisc */
    VPI_MEMSET(&sockparams, 0, sizeof(sockparams));
    sockparams.mr_type = PACKET_MR_PROMISC;
    sockparams.mr_ifindex = nvi->ifindex;
    if(setsockopt(nvi->fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP,
                  (void *)&sockparams, sizeof(sockparams)) < 0) {
        VPI_ERROR(nvi, "setsockopt() promisc failed. %s\n", strerror(errno));
        close(nvi->fd);
        aim_free(nvi);
        return -1;
    }

    /* Set up rx_ring buffer */
    VPI_MEMSET(&treq, 0, sizeof(treq));
    treq.tp_block_size = BLOCK_SIZE;
    treq.tp_frame_size = FRAME_SIZE;
    treq.tp_block_nr = NUM_BLOCKS;
    treq.tp_frame_nr = NUM_FRAMES;;
    if(setsockopt(nvi->fd, SOL_PACKET, PACKET_RX_RING,
                  (void*)&treq , sizeof(treq)) < 0) {
        VPI_ERROR(nvi, "setsockopt() rx_ring failed. %s\n", strerror(errno));
        close(nvi->fd);
        aim_free(nvi);
        return -1;
    }

    /* If num blocks change, bail! */
    if(treq.tp_block_nr != NUM_BLOCKS) {
        AIM_DIE("Unhandled: RX_RING block number changed!\n");
    }

    /* Set up rx_ring */
    nvi->rx_ring.buf = mmap(NULL, BLOCK_SIZE*NUM_BLOCKS,
                            PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED,
                            nvi->fd, 0);
    if(nvi->rx_ring.buf == MAP_FAILED) {
        VPI_ERROR(nvi, "mmap() failed.\n");
        close(nvi->fd);
        aim_free(nvi);
        return -1;
    }

    /* Set up rx_ring and frame controls */
    nvi->rx_ring.current_frame = 0;
    for(i = 0; i < NUM_FRAMES; i++) {
        fc = &nvi->rx_ring.frames[i];
        fc->base = nvi->rx_ring.buf + (i*FRAME_SIZE);
    }

    /* Bind */
    VPI_MEMSET(&sockaddr, 0, sizeof(sockaddr));
    sockaddr.sll_family = AF_PACKET;
    sockaddr.sll_protocol = htons(ETH_P_ALL);
    sockaddr.sll_ifindex = nvi->ifindex;
    if(bind(nvi->fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) < 0) {
        VPI_ERROR(nvi, "bind() failed.\n");
        close(nvi->fd);
        aim_free(nvi);
        return -1;
    }

    nvi->interface.send = vpi_mmap_interface_send;
    nvi->interface.recv = vpi_mmap_interface_recv;
    nvi->interface.recv_ready = vpi_mmap_interface_recv_ready;
    nvi->interface.destroy = vpi_mmap_interface_destroy;
    nvi->interface.descriptor = vpi_mmap_interface_descriptor;

    *vi = (vpi_interface_t*)nvi;
    return 0;
}
コード例 #3
0
int
vpi_veth_interface_create(vpi_interface_t** vi, char* args[], int flags,
                       const char* vpi_name_ptr)
{
    struct sockaddr_ll sockaddr;
    struct ifreq ifreq;
    vpi_interface_veth_t* nvi = aim_zmalloc(sizeof(*nvi));
    char** arg = args;

    AIM_REFERENCE(flags);

    if(nvi == NULL) {
        VPI_MERROR("interface allocation failed for %s.",
                   vpi_name_ptr);
        return -1;
    }

    /*
     * Point our log_string to our name so we can use it immediately
     * in log messages.
     */
    nvi->log_string = vpi_name_ptr;


    /*
     * The first argument is the type -- skip for now
     */
    arg++;

    aim_strlcpy(nvi->interface_name, *arg, sizeof(nvi->interface_name));

    /* Create RAW socket */
    if((nvi->fd = socket(PF_PACKET, SOCK_RAW, 0)) < 0) {
        VPI_ERROR(nvi, "socket() failed: %s\n", strerror(errno));
        aim_free(nvi);
        return -1;
    }

    /*
     * Get the interface index for the requested interface, as specified
     * in the current argument.
     */

    VPI_MEMSET(&ifreq, 0, sizeof(ifreq));
    aim_strlcpy(ifreq.ifr_name, nvi->interface_name, IFNAMSIZ);

    if(ioctl(nvi->fd, SIOCGIFINDEX, &ifreq) < 0) {
        VPI_ERROR(nvi, "ioctl() failed: %s", strerror(errno));
        close(nvi->fd);
        aim_free(nvi);
        return -1;
    }
    nvi->ifindex = ifreq.ifr_ifindex;

    VPI_INFO(nvi, "ifndex is %d", nvi->ifindex);

    VPI_MEMSET(&sockaddr, 0, sizeof(sockaddr));
    sockaddr.sll_family=AF_PACKET;
    sockaddr.sll_protocol = htons(ETH_P_ALL);
    sockaddr.sll_ifindex = ifreq.ifr_ifindex;

    if(bind(nvi->fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) < 0) {
        VPI_ERROR(nvi, "bind() failed");
        return -1;
    }

    nvi->interface.send = vpi_veth_interface_send;
    nvi->interface.recv = vpi_veth_interface_recv;
    nvi->interface.recv_ready = vpi_veth_interface_recv_ready;
    nvi->interface.destroy = vpi_veth_interface_destroy;
    nvi->interface.descriptor = vpi_veth_interface_descriptor;

    *vi = (vpi_interface_t*)nvi;
    return 0;
}
コード例 #4
0
int
faultd_handler_register(int localfd, 
                        const char* pipename, 
                        const char* binaryname)
{
    int rv; 
    struct sigaction saction; 
    void* dummy_backtrace[1]; 
    int dummy_backtrace_size; 
    int fd; 

    if ( (rv = pthread_spin_init(&thread_lock__, 0)) ) { 
        return rv; 
    }

    /* 
     * These calls to backtrace are to assure that 
     * backtrace() and backtrace_symbols_fd() have actually 
     * been loaded into our process -- its possible they 
     * come from a dynamic library, and we don't want them
     * to get loaded at fault-time.
     */
    dummy_backtrace_size = backtrace(dummy_backtrace, 1); 
    
    /** Note - we could just pass an invalid descriptor here, but it 
     * it flags errors in valgrind. 
     */
    fd = open("/dev/null", O_WRONLY); 
    backtrace_symbols_fd(dummy_backtrace, dummy_backtrace_size, fd); 
    close(fd); 

    AIM_MEMSET(&faultd_info__, 0, sizeof(faultd_info__)); 
    if(!binaryname) { 
        binaryname = "Not specified."; 
    }
    aim_strlcpy(faultd_info__.binary, binaryname, sizeof(faultd_info__.binary)); 
                

    if(pipename) { 
        faultd_client_create(&faultd_client__, pipename); 
    }

    AIM_MEMSET(&saction, 0, sizeof(saction)); 
    saction.sa_sigaction = faultd_signal_handler__; 

    sigfillset(&saction.sa_mask); 
    saction.sa_flags = SA_SIGINFO | SA_RESETHAND; 
    
    rv = sigaction (SIGSEGV, &saction, NULL); 
    rv |= sigaction (SIGILL, &saction, NULL);
    rv |= sigaction (SIGFPE, &saction, NULL);  
    rv |= sigaction (SIGBUS, &saction, NULL);
    rv |= sigaction (SIGQUIT, &saction, NULL);
    rv |= sigaction (SIGALRM, &saction, NULL);

    /*
     * SIGUSR2 can be used to request a backtrace explicitly. 
     * In this case, we don't want to reset the handler. 
     */
    saction.sa_flags = SA_SIGINFO; 
    rv |= sigaction (SIGUSR2, &saction, NULL);  

    /*
     * The local fault handler will attempt to write a subset of
     * the fault information (signal type and backtrace) 
     * to the localfd descriptor if specified. 
     */
    localfd__ = localfd; 

    return rv;
}
コード例 #5
0
int
vpi_pcapdump_interface_create(vpi_interface_t** vi, char* args[], int flags,
                              const char* vpi_name_ptr)
{
    vpi_interface_pcapdump_t* nvi = aim_zmalloc(sizeof(*nvi));
    char** arg = args;
    char errbuf[PCAP_ERRBUF_SIZE];

    AIM_REFERENCE(flags);

    if(nvi == NULL) {
        VPI_MERROR("interface allocation failed for %s.",
                   vpi_name_ptr);
        return -1;
    }

    /*
     * Point our log_string to our name so we can use it immediately
     * in log messages.
     */
    nvi->log_string = vpi_name_ptr;


    /*
     * The first argument is the type -- skip for now
     */
    arg++;

    if((nvi->pcap = pcap_open_dead(DLT_EN10MB, 10000)) == NULL) {
        VPI_ERROR(nvi, "pcap_open_dead() failed: %s\n",
                  *arg, errbuf);
        aim_free(nvi);
        return -1;
    }

    /*
     * next arg - filename name.
     */
    if((nvi->pcap_dumper = pcap_dump_open(nvi->pcap, *arg)) == NULL) {
        VPI_ERROR(nvi, "pcap_dump_open(%s) failed\n", *arg);
        pcap_close(nvi->pcap);
        aim_free(nvi);
        return -1;
    }

    arg++;
    if(*arg) {
        /*
         * if the next arg is 'mpls', packets will be encapsulated
         * in an MPLS frame with the outer fields indicating useful
         * information, like port number, send or recieved, etc
         */
        if(!VPI_STRCMP(*arg, "mpls")) {
            nvi->mpls = 1;
        }
        arg++;
        if(*arg) {
            /*
             * Set the label field
             */
            aim_strlcpy(nvi->ident, *arg, sizeof(nvi->ident));
        }
    }

    nvi->interface.send = vpi_pcapdump_interface_send;
    nvi->interface.recv = NULL;
    nvi->interface.recv_ready = NULL;
    nvi->interface.destroy = vpi_pcapdump_interface_destroy;
    nvi->interface.descriptor = NULL;

    *vi = (vpi_interface_t*)nvi;
    return 0;
}