static bool write_chunk_sqlite(const unsigned char *chunk, const unsigned char *digest, void *db_info_ptr) { static const char sql[] = "INSERT OR IGNORE INTO chunk(hash, data) VALUES(?,?)"; struct db_info *db_info = db_info_ptr; sqlite3_stmt *stmt; int err; lock_db(db_info); err = sqlite3_prepare(db_info->db, sql, -1, &stmt, 0); if (err != SQLITE_OK) { ERROR("sqlite3_prepare failed: %s\n", sqlite3_errmsg(db_info->db)); unlock_db(db_info); return false; } sqlite3_bind_text(stmt, 1, digest_string(digest), -1, SQLITE_STATIC); sqlite3_bind_blob(stmt, 2, chunk, CHUNK_SIZE, SQLITE_STATIC); err = sqlite3_step(stmt); assert(err != SQLITE_ROW); if (sqlite3_finalize(stmt) != SQLITE_OK) { ERROR("sqlite3_finalize failed: %s\n", sqlite3_errmsg(db_info->db)); unlock_db(db_info); return false; } unlock_db(db_info); return true; }
/* * Leave debugger. */ void db_leave() { int mycpu = cpu_number(); /* * If continuing, give up debugger */ if (db_run_mode == STEP_CONTINUE) db_cpu = -1; /* * If I am a slave, drop my slave count. */ if (db_slave[mycpu]) db_slave[mycpu]--; if (db_enter_debug) db_printf("db_leave: cpu %d[%d], db_cpu %d, run_mode %d\n", mycpu, db_slave[mycpu], db_cpu, db_run_mode); /* * Unlock debugger. */ unlock_db(); /* * Drop recursive entry count. */ db_active[mycpu]--; }
void mp_bundle_terminated() { TDB_DATA key; bundle_terminating = 1; upper_layers_down(pcb); notice("Connection terminated."); #if PPP_STATS_SUPPORT print_link_stats(); #endif /* PPP_STATS_SUPPORT */ if (!demand) { remove_pidfiles(); script_unsetenv("IFNAME"); } lock_db(); destroy_bundle(); iterate_bundle_links(sendhup); key.dptr = blinks_id; key.dsize = strlen(blinks_id); tdb_delete(pppdb, key); unlock_db(); new_phase(PPP_PHASE_DEAD); doing_multilink = 0; multilink_master = 0; }
/* * switch to another cpu */ void db_on(int cpu) { /* * Save ddb global variables */ DB_SAVE_CTXT(); /* * Don`t do if bad CPU number. * CPU must also be spinning in db_entry. */ if (cpu < 0 || cpu >= NCPUS || !db_active[cpu]) return; /* * Give debugger to that CPU */ db_cpu = cpu; unlock_db(); /* * Wait for it to come back again */ lock_db(); /* * Restore ddb globals */ DB_RESTORE_CTXT(); if (db_cpu == -1) /* someone continued */ db_continue_cmd(0, 0, 0, ""); }
static bool read_chunk_sqlite(unsigned char *chunk, const unsigned char *digest, void *db_info_ptr) { static const char sql[] = "SELECT data FROM chunk WHERE hash = ?"; struct db_info *db_info = db_info_ptr; sqlite3_stmt *stmt; int err; bool status = false; lock_db(db_info); err = sqlite3_prepare(db_info->db, sql, -1, &stmt, 0); if (err != SQLITE_OK) { ERROR("sqlite3_prepare failed: %d\n", sqlite3_errmsg(db_info->db)); unlock_db(db_info); return false; } TRACE("%s\n", digest_string(digest)); sqlite3_bind_text(stmt, 1, digest_string(digest), -1, SQLITE_STATIC); err = sqlite3_step(stmt); if (err != SQLITE_ROW) { ERROR("sqlite3_step failed: %s\n", sqlite3_errmsg(db_info->db)); } else if (sqlite3_column_bytes(stmt, 0) != CHUNK_SIZE) { ERROR("sqlite3 query returned %d bytes instead of %d.\n", sqlite3_column_bytes(stmt, 0), CHUNK_SIZE); } else { TRACE("sqlite3 query got chunk.\n"); memcpy(chunk, sqlite3_column_blob(stmt, 0), CHUNK_SIZE); status = true; } sqlite3_finalize(stmt); unlock_db(db_info); return status; }
void mp_exit_bundle() { lock_db(); remove_bundle_link(); unlock_db(); }
/* * Make a new bundle or join us to an existing bundle * if we are doing multilink. */ int mp_join_bundle() { lcp_options *go = &lcp_gotoptions[0]; lcp_options *ho = &lcp_hisoptions[0]; lcp_options *ao = &lcp_allowoptions[0]; int unit, pppd_pid; int l, mtu; char *p; TDB_DATA key, pid, rec; if (doing_multilink) { /* have previously joined a bundle */ if (!go->neg_mrru || !ho->neg_mrru) { notice("oops, didn't get multilink on renegotiation"); lcp_close(pcb, "multilink required"); return 0; } /* XXX should check the peer_authname and ho->endpoint are the same as previously */ return 0; } if (!go->neg_mrru || !ho->neg_mrru) { /* not doing multilink */ if (go->neg_mrru) notice("oops, multilink negotiated only for receive"); mtu = ho->neg_mru? ho->mru: PPP_MRU; if (mtu > ao->mru) mtu = ao->mru; if (demand) { /* already have a bundle */ cfg_bundle(0, 0, 0, 0); netif_set_mtu(pcb, mtu); return 0; } make_new_bundle(0, 0, 0, 0); set_ifunit(1); netif_set_mtu(pcb, mtu); return 0; } doing_multilink = 1; /* * Find the appropriate bundle or join a new one. * First we make up a name for the bundle. * The length estimate is worst-case assuming every * character has to be quoted. */ l = 4 * strlen(peer_authname) + 10; if (ho->neg_endpoint) l += 3 * ho->endpoint.length + 8; if (bundle_name) l += 3 * strlen(bundle_name) + 2; bundle_id = malloc(l); if (bundle_id == 0) novm("bundle identifier"); p = bundle_id; p += slprintf(p, l-1, "BUNDLE=\"%q\"", peer_authname); if (ho->neg_endpoint || bundle_name) *p++ = '/'; if (ho->neg_endpoint) p += slprintf(p, bundle_id+l-p, "%s", epdisc_to_str(&ho->endpoint)); if (bundle_name) p += slprintf(p, bundle_id+l-p, "/%v", bundle_name); /* Make the key for the list of links belonging to the bundle */ l = p - bundle_id; blinks_id = malloc(l + 7); if (blinks_id == NULL) novm("bundle links key"); slprintf(blinks_id, l + 7, "BUNDLE_LINKS=%s", bundle_id + 7); /* * For demand mode, we only need to configure the bundle * and attach the link. */ mtu = LWIP_MIN(ho->mrru, ao->mru); if (demand) { cfg_bundle(go->mrru, ho->mrru, go->neg_ssnhf, ho->neg_ssnhf); netif_set_mtu(pcb, mtu); script_setenv("BUNDLE", bundle_id + 7, 1); return 0; } /* * Check if the bundle ID is already in the database. */ unit = -1; lock_db(); key.dptr = bundle_id; key.dsize = p - bundle_id; pid = tdb_fetch(pppdb, key); if (pid.dptr != NULL) { /* bundle ID exists, see if the pppd record exists */ rec = tdb_fetch(pppdb, pid); if (rec.dptr != NULL && rec.dsize > 0) { /* make sure the string is null-terminated */ rec.dptr[rec.dsize-1] = 0; /* parse the interface number */ parse_num(rec.dptr, "IFNAME=ppp", &unit); /* check the pid value */ if (!parse_num(rec.dptr, "PPPD_PID=", &pppd_pid) || !process_exists(pppd_pid) || !owns_unit(pid, unit)) unit = -1; free(rec.dptr); } free(pid.dptr); } if (unit >= 0) { /* attach to existing unit */ if (bundle_attach(unit)) { set_ifunit(0); script_setenv("BUNDLE", bundle_id + 7, 0); make_bundle_links(1); unlock_db(); info("Link attached to %s", ifname); return 1; } /* attach failed because bundle doesn't exist */ } /* we have to make a new bundle */ make_new_bundle(go->mrru, ho->mrru, go->neg_ssnhf, ho->neg_ssnhf); set_ifunit(1); netif_set_mtu(pcb, mtu); script_setenv("BUNDLE", bundle_id + 7, 1); make_bundle_links(pcb); unlock_db(); info("New bundle %s created", ifname); multilink_master = 1; return 0; }