Changeset 1593

Show
Ignore:
Timestamp:
03/06/08 19:57:26 (6 months ago)
Author:
till
Message:

nebula
- polling corrected

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nebula/trunk/ChangeLog

    r1588 r1593  
    110.2.1 
     2- polling corrected 
    23- port and protocol added to signatures 
    34- signature hash fixed 
  • nebula/trunk/src/hash.c

    r1558 r1593  
    5151        ((hash *)h)->sha512sum = NULL; 
    5252 
    53         session_reset(((hash *)h)->submission, NULL); 
     53        session_reset(((hash *)h)->submission, -1); 
    5454        free(((hash *)h)->submission); 
    5555        ((hash *)h)->submission = NULL; 
  • nebula/trunk/src/nebula.c

    r1585 r1593  
    2828#include <stdio.h> 
    2929#include <sys/mman.h> 
     30#include <sys/resource.h> 
    3031#include <sys/stat.h> 
    3132#include <sys/types.h> 
     
    8081        submission      s[POLLFD_SET_SIZE], *tmp_submission; 
    8182        pthread_attr_t  ptattr; 
    82  
    83  
    84         memset(pfdset, -1, sizeof(struct pollfd) * (POLLFD_SET_SIZE+1)); 
     83        struct rlimit   rlim; 
     84 
     85 
     86        memset(pfdset, 0, sizeof(struct pollfd) * (POLLFD_SET_SIZE+1)); 
     87        memset(pfdflag, 0, sizeof(u_char) * (POLLFD_SET_SIZE)); 
    8588        memset(s, 0, sizeof(submission) * POLLFD_SET_SIZE); 
    8689 
     
    210213        set_signal_handlers(); 
    211214 
     215 
     216        // increase maximum number of open files if necessary 
     217        memset(&rlim, 0, sizeof(struct rlimit)); 
     218        if (getrlimit(RLIMIT_NOFILE, &rlim) == -1) { 
     219                fprintf(stderr, "Error - Unable to get maximum number of open files: %s.\n", strerror(errno)); 
     220                exit(EXIT_FAILURE); 
     221        } 
     222        if (rlim.rlim_max < POLLFD_SET_SIZE+1) { 
     223                rlim.rlim_max = rlim.rlim_cur = POLLFD_SET_SIZE+1; 
     224                if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) { 
     225                        fprintf(stderr, "Error - Unable to increase maximum number of open files: %s.\n", strerror(errno)); 
     226                        exit(EXIT_FAILURE); 
     227                } 
     228                if (verbose) printf("  Maximum number of open files increased to %u.\n", (unsigned int) rlim.rlim_cur); 
     229        } 
     230 
     231 
    212232        // initialize HMAC pads 
    213233        memset(k_ipad, IPAD_VAL, HMAC_BLOCK_SIZE); 
     
    250270        LISTEN_SOCK.fd          = listen_fd; 
    251271        LISTEN_SOCK.events      = POLLIN; 
     272 
    252273        for(;;) { 
    253274                switch (rv = poll(pfdset, POLLFD_SET_SIZE+1, -1)) { 
     
    282303                                                        pfdset[i].fd            = net_accept(LISTEN_SOCK.fd); 
    283304                                                        pfdset[i].events        = POLLOUT; 
     305                                                        pfdflag[i]              = 1; 
    284306 
    285307                                                        memset(&s[i], 0, sizeof(submission)); 
     
    294316                        } 
    295317                        for (i=0; i<POLLFD_SET_SIZE; i++) { 
    296                                 if (pfdset[i].revents & POLLOUT) { 
     318                                if (pfdflag[i] && pfdset[i].revents & POLLOUT) { 
    297319                                        switch (session_handle_data(&pfdset[i], &s[i])) { 
    298320                                        case -1: 
    299321                                                fprintf(stderr, "Error - Invalid submission state. Terminating session.\n"); 
    300                                                 session_reset(&s[i], &pfdset[i]); 
     322                                                session_reset(&s[i], i); 
    301323                                                break; 
    302324                                        case 0: 
    303                                                 session_reset(&s[i], &pfdset[i]); 
     325                                                session_reset(&s[i], i); 
    304326                                                break; 
    305327                                        default: 
     
    308330                                        } 
    309331                                } 
    310                                 if (pfdset[i].revents) { 
     332                                if (pfdflag[i] && pfdset[i].revents) { 
    311333                                        if (pfdset[i].revents & POLLIN) { 
    312334                                                switch (session_handle_data(&pfdset[i], &s[i])) { 
     
    335357                                                        pthread_attr_destroy(&ptattr); 
    336358 
    337                                                         session_reset(&s[i], &pfdset[i]); 
     359                                                        session_reset(&s[i], i); 
    338360                                                        break; 
    339361                                                case 0: 
    340362                                                        // connection closed 
    341                                                         session_reset(&s[i], &pfdset[i]); 
     363                                                        session_reset(&s[i], i); 
    342364                                                        break; 
    343365                                                case -1: 
    344366                                                        // program error 
    345367                                                        fprintf(stderr, "Error - Terminating session.\n"); 
    346                                                         session_reset(&s[i], &pfdset[i]); 
     368                                                        session_reset(&s[i], i); 
    347369                                                        break; 
    348370                                                case -2: 
    349371                                                        // connection state error 
    350372                                                        fprintf(stderr, "Error - Invalid connection state.\n"); 
    351                                                         session_reset(&s[i], &pfdset[i]); 
     373                                                        session_reset(&s[i], i); 
    352374                                                        break; 
    353375                                                default: 
     
    356378                                        } else if (pfdset[i].revents & POLLERR && errno != EINTR) { 
    357379                                                fprintf(stderr, "Error - Unable to poll socket: %s.\n", strerror(errno)); 
    358                                                 session_reset(&s[i], &pfdset[i]); 
     380                                                session_reset(&s[i], i); 
    359381                                        } else if (pfdset[i].revents & POLLHUP) { 
    360382                                                fprintf(stderr, "Error - Socket hangup.\n"); 
    361                                                 session_reset(&s[i], &pfdset[i]); 
     383                                                session_reset(&s[i], i); 
    362384                                        } else if (pfdset[i].revents & POLLNVAL) { 
    363385                                                fprintf(stderr, "Error - Socket descriptor is invalid.\n"); 
    364                                                 session_reset(&s[i], &pfdset[i]); 
     386                                                session_reset(&s[i], i); 
    365387                                        } 
    366388                                } 
  • nebula/trunk/src/nebula.h

    r1566 r1593  
    3636 
    3737 
    38 #define POLLFD_SET_SIZE 1023 
     38#define POLLFD_SET_SIZE 255 
    3939#define LISTEN_SOCK     pfdset[POLLFD_SET_SIZE] 
    4040 
    4141struct pollfd   pfdset[POLLFD_SET_SIZE+1]; 
     42u_char          pfdflag[POLLFD_SET_SIZE]; 
    4243 
    4344int             lock_mutex; 
  • nebula/trunk/src/session.c

    r1588 r1593  
    3535 
    3636 
    37 void session_reset(submission *s, struct pollfd *pfd) { 
     37void session_reset(submission *s, int session_number) { 
    3838        if (!s) return; 
    3939 
     
    4646        memset(s, 0, sizeof(submission)); 
    4747 
    48         if (pfd) { 
    49                 if (pfd->fd >= 0) close(pfd->fd); 
     48        if (session_number >= 0 && pfdflag[session_number]) { 
     49                if (pfdset[session_number].fd >= 0) close(pfdset[session_number].fd); 
    5050                if (verbose > 1) printf("[<] Connection terminated.\n"); 
    5151 
    52                 memset(pfd, 0, sizeof(struct pollfd)); 
    53                 pfd->events   = 0; 
    54                 pfd->fd                = -1; 
     52                memset(&pfdset[session_number], 0, sizeof(struct pollfd)); 
     53                pfdset[session_number].events = 0; 
     54                pfdflag[session_number]                = 0;    // mark fd as unused 
    5555        } 
    5656 
  • nebula/trunk/src/session.h

    r1568 r1593  
    5858 
    5959typedef struct submission { 
     60        u_int32_t       session_number;         // session number in array 
    6061        sstate          state;                  // session state 
    6162        u_int32_t       bytes_read;             // number of bytes read so far 
     
    7879 
    7980 
    80 void session_reset(submission *s, struct pollfd *pfd); 
     81void session_reset(submission *s, int session_number); 
    8182char *session_hmac(u_char **msg, ssize_t len); 
    8283int session_handle_data(struct pollfd *pfd, submission *s);