int destroy_vxlan_instance (struct vxlan_instance * vins) { /* error handling */ if (vxlan.vins_num < 1) { return -1; } if (vins == NULL) { error_warn ("%s: vxlan_instance is NULL!!", __func__); return -1; } /* Stop And Delete */ if (pthread_cancel (vins->tid) != 0) error_warn ("%s: can not stop vxlan instance %s", vins->vxlan_tap_name); if (close (vins->tap_sock) < 0) error_warn ("%s: can not close tap socket %s : %s", vins->vxlan_tap_name, strerror (errno)); destroy_fdb (vins->fdb); /* cleaning struct vxlan values */ vxlan.vins_num--; delete_hash (&vxlan.vins_tuple, vins->vni); return 0; }
void * process_vxlan_control (void * param) { char * c; int socket, accept_socket; char buf[CONTROL_MSG_BUF_LEN]; fd_set fds; socket = create_unix_server_socket (VXLAN_UNIX_DOMAIN); vxlan.control_sock = socket; listen (socket, 1); while (1) { memset (buf, 0, sizeof (buf)); FD_ZERO (&fds); FD_SET (socket, &fds); pselect (socket + 1, &fds, NULL, NULL, NULL, NULL); if (!FD_ISSET (socket, &fds)) break; accept_socket = accept (socket, NULL, 0); if (read (accept_socket, buf, sizeof (buf)) < 0) { warn ("read(2) faild : control socket"); shutdown (accept_socket, 1); close (accept_socket); continue; } for (c = buf; *c == ' '; c++); exec_command_func[strtocmdtype (c)] (c, accept_socket); if (shutdown (accept_socket, SHUT_RDWR) != 0) { error_warn ("%s : shutdown : %s", __func__, strerror (errno)); } if (close (accept_socket) != 0) { error_warn ("%s : close : %s", __func__, strerror (errno)); } } shutdown (vxlan.control_sock, SHUT_RDWR); if (close (vxlan.control_sock) < 0) error_warn ("%s : close control socket failed : %s", strerror (errno)); /* not reached */ return NULL; }
static signed int clean_buff(char **buffer, char *alphabet) { char *p, *c; int bufflen; p = *buffer; c = *buffer; bufflen = 0; while (*p && *p != '\n') { if (isspace ((int)*p)) { p++; continue; } if( alphabet[(int)*p] != '\0') { *c++ = alphabet[(int)*p]; p++; bufflen++; } else { if (isalpha((int)*p) || *p == '*') { char err_aa[2]; err_aa[0] = *p; err_aa[1] = '\0'; error_warn(err_aa, "not a valid aa, skipped"); p++; } else { return -1; } } } *c = '\0'; return bufflen; }
static void process_header(seq_t *seq, char *header) { char *id, *comm, *p, *q; int i, n, l; n = 0; p = header; /* skip > */ p++; while(*p && isascii((int)*p) && !isspace((int)*p)) { p++; n++; } /* check if sequence is named or not */ if (n == 1 && strchr( ".,;", (int)header[1])) n = 0; l = ( n == 0) ? 9 : n; if((id = malloc(sizeof(char)*(l+1))) == NULL){ error_fatal("memory", NULL); } p = header; p++; /* check if sequence is named or not */ if ( n == 0 ){ error_warn("anonymous sequence", "name will be forced to \"anonymous\""); snprintf(id,10, "anonymous"); } else { q = id; for (i=0; i<n; i++) { /* replace all non alnum character by '_' */ if (isalnum((int)*p)) *q++ = *p++; else { *q++ = '_'; p++; } } *q = '\0'; } /* skip spaces */ while(*p && (isspace((int)*p))) { p++; n++; } /* get comment */ if((comm = malloc(sizeof(char) * (strlen(header) - n))) == NULL){ error_fatal("memory", "COMLEN"); } q = comm; while(*p && *p != '\n') { *q++ = *p++; } *q = '\0'; seq->id = id; seq->comment = comm; }
void strtocontrol (char * str) { char type[16]; char args[512]; if (sscanf (str, "%s %s", type, args) < 2) { error_warn ("invalid control message \"%s\"", str); return; } return; }
void * process_vxlan_instance (void * param) { int len; char buf[VXLAN_PACKET_BUF_LEN]; struct vxlan_instance * vins; fd_set fds; vins = (struct vxlan_instance *) param; #ifdef DEBUG printf ("vxlan instance\n"); printf ("IFNAME : %s\n", vins->vxlan_tap_name); printf ("SOCKET : %d\n", vins->tap_sock); #endif /* From Tap */ while (1) { FD_ZERO (&fds); FD_SET (vins->tap_sock, &fds); pselect (vins->tap_sock + 1, &fds, NULL, NULL, NULL, NULL); if (!FD_ISSET (vins->tap_sock, &fds)) break; if ((len = read (vins->tap_sock, buf, sizeof (buf))) < 0) { error_warn ("read from tap socket failed %s", strerror (errno)); continue; } send_etherflame_from_local_to_vxlan (vins, (struct ether_header * )buf, len); } /* not reached */ return NULL; }
int read_seq(FILE *IN, seq_t *seq_holder) { char *BUFF, *id, *comment, *seq, *p, *q; int i, state, n, n_tot, len; n_tot = BUFFLEN; n = 0; len = BUFFLEN; if((BUFF = malloc(sizeof(char) * (BUFFLEN + 1))) == NULL){ error_fatal("memory", NULL); } p = NULL; /* procces id and comment */ state = COMMENT; while ((fgets(BUFF, len, IN)) != NULL) { /* comment line is not complety read */ if (strrchr(BUFF, '\n') == NULL) { len += BUFFLEN; if((BUFF = realloc(BUFF, sizeof(char)*len)) == NULL) { error_fatal("memory realloc", NULL); } if(fseek(IN, -1 *(long)strlen(BUFF), SEEK_CUR)){ error_fatal("fseek", "fseek"); } continue; } /* procces id and comment */ else{ p = BUFF; if (*p != '>') { error_fatal("file", "not in fasta format"); } p++; while(*p && !isspace((int)*p)) { p++; n++; } /* check if sequence is named or not */ if((n == 0) || (n == 1 && ispunct((int)BUFF[1]))) { if((id = malloc(sizeof(char)*(9+1))) == NULL){ error_fatal("memory", NULL); } error_warn("anonymous sequence", "name will be forced to \"anonymous\""); snprintf(id,10, "anonymous"); } else { if((id = malloc(sizeof(char)*(n+1))) == NULL){ error_fatal("memory", NULL); } q = id; p = BUFF; p++; for(i = 0; i<n; i++){ *q++ = *p++; } *q = '\0'; } while(*p && (isspace((int)*p) || ispunct((int)*p))) p++; if((comment = malloc((strlen(BUFF) - n)*sizeof(char))) == NULL){ error_fatal("memory", "COMLEN"); } q = comment; while(*p && *p != '\n') *q++ = *p++; *q = '\0'; state = SEQ; break; } } n = 0; /*process sequence */ if(state == SEQ){ if((seq = malloc(sizeof(char)* (BUFFLEN+1))) == NULL) { error_fatal("memory", NULL); } q =seq; while((fgets(BUFF, BUFFLEN, IN)) != NULL) { p = BUFF; /* allow multiple sequence files to be proceced */ if (state == SEQ && *p && *p == '>') { /* replace the buffer on input*/ if(fseek(IN, -1 * strlen(p), SEEK_CUR) == -1) { error_fatal("fseek", NULL); } break; } /* check if seq buffer is big enough */ if ((n + strlen(p)) > n_tot) { n_tot += BUFFLEN; if ((seq = (char *)realloc(seq, n_tot*sizeof(char))) == NULL) { error_fatal("Reallocating seq", NULL); } q = seq + n; } while(*p && *p != '\n') { if(!isascii((int)*p)) { error_fatal("sequence", "contain non ascii characters"); } if(isspace((int)*p)) { p++; continue; } n++; *q++ = *p++; } } *q = '\0'; if(n == 0){ error_fatal(id, "empty sequence"); } /* correct id so that it does not contain \/ */ if((q = strrchr(id, '/')) != NULL) { p = id; while(*q) { *p++ = *++q; } *p = '\0'; } /* easiest way to unhide some files, dot is switched to _ */ if(*id == '.') { *id = '_'; } seq_holder->id = id; seq_holder->comment = comment; seq_holder->seq = seq; seq_holder->size = n; } else { seq_holder->id = NULL; seq_holder->comment = NULL; seq_holder->seq = NULL; seq_holder->size = 0; } free(BUFF); return state; }