/* * Things that need to happen immediately after connection initiation should go here. */ void check_connection_established_dowork (struct context *c) { if (event_timeout_trigger (&c->c2.wait_for_connect, &c->c2.timeval, ETT_DEFAULT)) { if (CONNECTION_ESTABLISHED (c)) { #if P2MP /* if --pull was specified, send a push request to server */ if (c->c2.tls_multi && c->options.pull) { #ifdef ENABLE_MANAGEMENT if (management) { management_set_state (management, OPENVPN_STATE_GET_CONFIG, NULL, 0, 0); } #endif /* send push request in 1 sec */ event_timeout_init (&c->c2.push_request_interval, 1, now); reset_coarse_timers (c); } else #endif { do_up (c, false, 0); } event_timeout_clear (&c->c2.wait_for_connect); } } }
void incoming_push_message (struct context *c, const struct buffer *buffer) { struct gc_arena gc = gc_new (); unsigned int option_types_found = 0; int status; msg (D_PUSH, "PUSH: Received control message: '%s'", sanitize_control_message(BSTR(buffer), &gc)); status = process_incoming_push_msg (c, buffer, c->options.pull, pull_permission_mask (c), &option_types_found); if (status == PUSH_MSG_ERROR) msg (D_PUSH_ERRORS, "WARNING: Received bad push/pull message: %s", sanitize_control_message(BSTR(buffer), &gc)); else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found; if (status == PUSH_MSG_REPLY) do_up (c, true, c->options.push_option_types_found ); /* delay bringing tun/tap up until --push parms received from remote */ event_timeout_clear (&c->c2.push_request_interval); } gc_free (&gc); }
/* Move up one line. */ void do_up_void(void) { do_up( #ifndef NANO_TINY FALSE #endif ); }
void do_sel(char key){ if (key == NORTH_BUTT.key){ do_up(); } else if(key == SOUTH_BUTT.key){ do_down(); } }
void incoming_push_message(struct context *c, const struct buffer *buffer) { struct gc_arena gc = gc_new(); unsigned int option_types_found = 0; int status; msg(D_PUSH, "PUSH: Received control message: '%s'", sanitize_control_message(BSTR(buffer), &gc)); status = process_incoming_push_msg(c, buffer, c->options.pull, pull_permission_mask(c), &option_types_found); if (status == PUSH_MSG_ERROR) { msg(D_PUSH_ERRORS, "WARNING: Received bad push/pull message: %s", sanitize_control_message(BSTR(buffer), &gc)); } else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found; /* delay bringing tun/tap up until --push parms received from remote */ if (status == PUSH_MSG_REPLY) { if (!do_up(c, true, c->options.push_option_types_found)) { msg(D_PUSH_ERRORS, "Failed to open tun/tap interface"); goto error; } } event_timeout_clear(&c->c2.push_request_interval); } else if (status == PUSH_MSG_REQUEST) { if (c->options.mode == MODE_SERVER) { struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE]; /* Do not regenerate keys if client send a second push request */ if (!session->key[KS_PRIMARY].crypto_options.key_ctx_bi.initialized && !tls_session_update_crypto_params(session, &c->options, &c->c2.frame)) { msg(D_TLS_ERRORS, "TLS Error: initializing data channel failed"); goto error; } } } goto cleanup; error: register_signal(c, SIGUSR1, "process-push-msg-failed"); cleanup: gc_free(&gc); }
int main(int argc, char *argv[]) { if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) help(); f = open("/dev/rtnet", O_RDWR); if (f < 0) { perror("/dev/rtnet"); exit(1); } if (argc == 1) do_display(PRINT_FLAG_ALL); if (strcmp(argv[1], "-a") == 0) { if (argc == 3) { strncpy(cmd.head.if_name, argv[2], IFNAMSIZ); do_display(PRINT_FLAG_INACTIVE); } else do_display(PRINT_FLAG_INACTIVE | PRINT_FLAG_ALL); } else strncpy(cmd.head.if_name, argv[1], IFNAMSIZ); if (argc < 3) do_display(0); if (strcmp(argv[2], "up") == 0) do_up(argc,argv); if (strcmp(argv[2], "down") == 0) do_down(argc,argv); help(); return 0; }
/* Scroll up one line without scrolling the cursor. */ void do_scroll_up(void) { do_up(TRUE); }
/*===========================================================================* * main * *===========================================================================*/ PUBLIC int main(void) { /* This is the main routine of this service. The main loop consists of * three major activities: getting new work, processing the work, and * sending the reply. The loop never terminates, unless a panic occurs. */ message m; /* request message */ int ipc_status; /* status code */ int call_nr, who_e,who_p; /* call number and caller */ int result; /* result to return */ int s; /* SEF local startup. */ sef_local_startup(); if (OK != (s=sys_getmachine(&machine))) panic("couldn't get machine info: %d", s); /* Main loop - get work and do it, forever. */ while (TRUE) { /* Wait for request message. */ get_work(&m, &ipc_status); who_e = m.m_source; if(rs_isokendpt(who_e, &who_p) != OK) { panic("message from bogus source: %d", who_e); } call_nr = m.m_type; /* Now determine what to do. Four types of requests are expected: * - Heartbeat messages (notifications from registered system services) * - System notifications (synchronous alarm) * - User requests (control messages to manage system services) * - Ready messages (reply messages from registered services) */ /* Notification messages are control messages and do not need a reply. * These include heartbeat messages and system notifications. */ if (is_ipc_notify(ipc_status)) { switch (who_p) { case CLOCK: do_period(&m); /* check services status */ continue; default: /* heartbeat notification */ if (rproc_ptr[who_p] != NULL) { /* mark heartbeat time */ rproc_ptr[who_p]->r_alive_tm = m.NOTIFY_TIMESTAMP; } else { printf("RS: warning: got unexpected notify message from %d\n", m.m_source); } } } /* If we get this far, this is a normal request. * Handle the request and send a reply to the caller. */ else { if (call_nr != COMMON_GETSYSINFO && (call_nr < RS_RQ_BASE || call_nr >= RS_RQ_BASE+0x100)) { /* Ignore invalid requests. Do not try to reply. */ printf("RS: warning: got invalid request %d from endpoint %d\n", call_nr, m.m_source); continue; } /* Handler functions are responsible for permission checking. */ switch(call_nr) { /* User requests. */ case RS_UP: result = do_up(&m); break; case RS_DOWN: result = do_down(&m); break; case RS_REFRESH: result = do_refresh(&m); break; case RS_RESTART: result = do_restart(&m); break; case RS_SHUTDOWN: result = do_shutdown(&m); break; case RS_UPDATE: result = do_update(&m); break; case RS_CLONE: result = do_clone(&m); break; case RS_EDIT: result = do_edit(&m); break; case COMMON_GETSYSINFO: result = do_getsysinfo(&m); break; case RS_LOOKUP: result = do_lookup(&m); break; /* Ready messages. */ case RS_INIT: result = do_init_ready(&m); break; case RS_LU_PREPARE: result = do_upd_ready(&m); break; default: printf("RS: warning: got unexpected request %d from %d\n", m.m_type, m.m_source); result = EINVAL; } /* Finally send reply message, unless disabled. */ if (result != EDONTREPLY) { m.m_type = result; reply(who_e, NULL, &m); } } } }
/*===========================================================================* * main * *===========================================================================*/ PUBLIC int main(void) { /* This is the main routine of this service. The main loop consists of * three major activities: getting new work, processing the work, and * sending the reply. The loop never terminates, unless a panic occurs. */ message m; /* request message */ int call_nr, who_e,who_p; /* call number and caller */ int result; /* result to return */ sigset_t sigset; /* system signal set */ int s; /* Initialize the server, then go to work. */ init_server(); /* Main loop - get work and do it, forever. */ while (TRUE) { /* Wait for request message. */ get_work(&m); who_e = m.m_source; who_p = _ENDPOINT_P(who_e); if(who_p < -NR_TASKS || who_p >= NR_PROCS) panic("RS","message from bogus source", who_e); call_nr = m.m_type; /* Now determine what to do. Three types of requests are expected: * - Heartbeat messages (notifications from registered system services) * - System notifications (POSIX signals or synchronous alarm) * - User requests (control messages to manage system services) */ /* Notification messages are control messages and do not need a reply. * These include heartbeat messages and system notifications. */ if (m.m_type & NOTIFY_MESSAGE) { switch (call_nr) { case SYN_ALARM: do_period(&m); /* check drivers status */ continue; case PROC_EVENT: sig_handler(); continue; default: /* heartbeat notification */ if (rproc_ptr[who_p] != NULL) /* mark heartbeat time */ rproc_ptr[who_p]->r_alive_tm = m.NOTIFY_TIMESTAMP; } } /* If this is not a notification message, it is a normal request. * Handle the request and send a reply to the caller. */ else { switch(call_nr) { case RS_UP: result = do_up(&m); break; case RS_DOWN: result = do_down(&m); break; case RS_REFRESH: result = do_refresh(&m); break; case RS_RESCUE: result = do_rescue(&m); break; case RS_SHUTDOWN: result = do_shutdown(&m); break; case GETSYSINFO: result = do_getsysinfo(&m); break; default: printf("Warning, RS got unexpected request %d from %d\n", m.m_type, m.m_source); result = EINVAL; } /* Finally send reply message, unless disabled. */ if (result != EDONTREPLY) { reply(who_e, result); } } } }
/* Move up one line. */ void do_up_void(void) { do_up(FALSE); }
void rwlock_write_up(rwlock_t *r) { do_up(r, RWLOCK_STATUS_WRITING); }
void rwlock_read_up(rwlock_t *r) { do_up(r, RWLOCK_STATUS_READING); }