extern "C" void InjectInterface(char*arg){ log_("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"); log_("*-*-*-*-*-* Injected so *-*-*-*-*-*-*-*"); log_("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"); Hook(); log_("*-*-*-*-*-*-*- End -*-*-*-*-*-*-*-*-*-*"); }
static int drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id) { drmDevicePtr device; int ret; if (drmGetDevice(fd, &device) == 0) { if (device->bustype == DRM_BUS_PCI) { *vendor_id = device->deviceinfo.pci->vendor_id; *chip_id = device->deviceinfo.pci->device_id; ret = 1; } else { log_(_LOADER_WARNING, "MESA-LOADER: device is not located on the PCI bus\n"); ret = 0; } drmFreeDevice(&device); } else { log_(_LOADER_WARNING, "MESA-LOADER: failed to retrieve device information\n"); ret = 0; } return ret; }
void* ComuactivClientSlot::ComuactivClientSlotImpl::run() { log_("Creating passive channels"); pLow_ = ProxyChannel(Channel::PASSIVE); pLow_.registerHandler( Message::HEARTBEAT, pHandler(new HeartbeatHandler() ) ); pLow_.start(); log_(std::string("Initialising connection to: ").append(host_).append(std::string(":")).append(highPort_)); high_ = ProxyChannel(Channel::ACTIVE); AssociationSetupResponseHandler::Callback aSRHcallback = std::bind(&ComuactivClientSlotImpl::stageTwo, this, std::placeholders::_1, std::placeholders::_2); high_.registerHandler( messages::Message::ASSOCIATION_SETUP_RESPONSE, pHandler( new AssociationSetupResponseHandler( aSRHcallback ) ) ); high_.setHost(host_); high_.setPort(highPort_); high_.start(); //TODO: synchronizacja sleep(1); pMessage msg = pAssociationSetupMsg( new AssociationSetupMsg( pLow_.getPort() ) ); high_.writeAndHandleMessage(msg->getRaw()); }
static inline struct udev_device * udev_device_new_from_fd(struct udev *udev, int fd) { struct udev_device *device; struct stat buf; UDEV_SYMBOL(struct udev_device *, udev_device_new_from_devnum, (struct udev *udev, char type, dev_t devnum)); if (dlsym_failed) return NULL; if (fstat(fd, &buf) < 0) { log_(_LOADER_WARNING, "MESA-LOADER: failed to stat fd %d\n", fd); return NULL; } device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev); if (device == NULL) { log_(_LOADER_WARNING, "MESA-LOADER: could not create udev device for fd %d\n", fd); return NULL; } return device; }
char * loader_get_driver_for_fd(int fd, unsigned driver_types) { int vendor_id, chip_id, i, j; char *driver = NULL; if (!driver_types) driver_types = _LOADER_GALLIUM | _LOADER_DRI; if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) { #ifndef __NOT_HAVE_DRM_H /* fallback to drmGetVersion(): */ drmVersionPtr version = drmGetVersion(fd); if (!version) { log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd); return NULL; } driver = strndup(version->name, version->name_len); log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd); drmFreeVersion(version); #endif return driver; } for (i = 0; driver_map[i].driver; i++) { if (vendor_id != driver_map[i].vendor_id) continue; if (!(driver_types & driver_map[i].driver_types)) continue; if (driver_map[i].predicate && !driver_map[i].predicate(fd)) continue; if (driver_map[i].num_chips_ids == -1) { driver = strdup(driver_map[i].driver); goto out; } for (j = 0; j < driver_map[i].num_chips_ids; j++) if (driver_map[i].chip_ids[j] == chip_id) { driver = strdup(driver_map[i].driver); goto out; } } out: log_(driver ? _LOADER_DEBUG : _LOADER_WARNING, "pci id for fd %d: %04x:%04x, driver %s\n", fd, vendor_id, chip_id, driver); return driver; }
static int libudev_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id) { struct udev *udev = NULL; struct udev_device *device = NULL, *parent; const char *pci_id; UDEV_SYMBOL(struct udev *, udev_new, (void)); UDEV_SYMBOL(struct udev_device *, udev_device_get_parent, (struct udev_device *)); UDEV_SYMBOL(const char *, udev_device_get_property_value, (struct udev_device *, const char *)); UDEV_SYMBOL(struct udev_device *, udev_device_unref, (struct udev_device *)); UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *)); *chip_id = -1; if (dlsym_failed) return 0; udev = udev_new(); device = udev_device_new_from_fd(udev, fd); if (!device) goto out; parent = udev_device_get_parent(device); if (parent == NULL) { log_(_LOADER_WARNING, "MESA-LOADER: could not get parent device\n"); goto out; } pci_id = udev_device_get_property_value(parent, "PCI_ID"); if (pci_id == NULL) { log_(_LOADER_INFO, "MESA-LOADER: no PCI ID\n"); *chip_id = -1; goto out; } else if (sscanf(pci_id, "%x:%x", vendor_id, chip_id) != 2) { log_(_LOADER_WARNING, "MESA-LOADER: malformed PCI ID\n"); *chip_id = -1; goto out; } out: if (device) udev_device_unref(device); if (udev) udev_unref(udev); return (*chip_id >= 0); }
void endbox_init() { int ret; struct rlimit limits; log_(NORM,"Initializing VPLS bridge\n"); ret = system("/usr/local/etc/hip/bridge_up.sh"); log_(NORM, "bridge_up.sh returns %d\n", ret); if (HCNF.endbox_allow_core_dump) { log_(NORM, "Setting limit on core size to max\n"); ret = getrlimit(RLIMIT_CORE, &limits); log_(NORM, "getrlimit returns %d\n", ret); log_(NORM, "Current is %u; max is %u\n", limits.rlim_cur, limits.rlim_max); limits.rlim_cur = limits.rlim_max; ret = setrlimit(RLIMIT_CORE, &limits); log_(NORM, "setrlimit returns %d\n", ret); ret = getrlimit(RLIMIT_CORE, &limits); log_(NORM, "getrlimit returns %d\n", ret); log_(NORM, "Current is %u; max is %u\n", limits.rlim_cur, limits.rlim_max); } return; }
int main(int argc, char **argv) { int err, publish; hip_hit hit; struct sockaddr_storage addr; struct sockaddr_in *addr4 = (struct sockaddr_in*)&addr; /* * Load hip.conf configuration file * user may have provided path using command line, or search defaults */ memset(HCNF, 0, sizeof(HCNF)); if ((locate_config_file(HCNF.conf_filename, sizeof(HCNF.conf_filename), HIP_CONF_FILENAME) < 0) || (read_conf_file(HCNF.conf_filename) < 0)) { log_(ERR, "Problem with configuration file, using defaults.\n"); } else { log_(NORM, "Using configuration file:\t%s\n", HCNF.conf_filename); } memset(&addr, 0, sizeof(addr)); addr4->sin_family = AF_INET; addr4->sin_addr.s_addr = inet_addr("192.168.1.2"); hex_to_bin("7BE901B3AF2679C8C580619535641713", hit, HIT_SIZE); printf("Doing XML RPC put 1...\n"); err = hip_dht_publish(&hit, (struct sockaddr*)&addr); printf("return value = %d\n", err); addr4->sin_addr.s_addr = inet_addr("192.168.2.7"); printf("Doing XML RPC put 2...\n"); err = hip_dht_publish(&hit, (struct sockaddr*)&addr); printf("return value = %d\n", err); memset(&addr, 0, sizeof(addr)); addr4->sin_family = AF_INET; printf("addr is at: %p\n", &addr); printf("Doing XML RPC get...\n"); err = hip_dht_lookup_address(&hit, (struct sockaddr*)&addr); printf("return value = %d\n", err); printf("Address = %s\n", logaddr((struct sockaddr*)&addr)); return(0); }
/* * Called from tunreader() * Send a hello using protocol IEEE Std 802 - Local Experimental Ethertype 1. * This lets other HIP daemons know that you are on the same subnet segment. */ void endbox_send_hello() { __u8 out[256]; __u64 dst_mac = 0xffffffffffffffffLL; int outlen = 0; hi_node *my_host_id; struct eb_hello *endbox_hello; /* Is my host id set yet? */ my_host_id = get_preferred_hi(my_hi_head); if (!my_host_id) { return; } add_eth_header(out, g_tap_mac, dst_mac, 0x88b5); endbox_hello = (struct eb_hello *) &out[14]; memcpy(endbox_hello->hit, my_host_id->hit, sizeof(hip_hit)); endbox_hello->time = htonl(HCNF.endbox_hello_time); outlen = sizeof(struct eth_hdr) + sizeof(struct arp_hdr) + 20; if (write(tapfd, out, outlen) < 0) { log_(WARN, "Sending endbox hello failed.\n"); } }
int SDMClient::close() { if (closed) { log_(ERROR, "client= " << client_name << " is already closed!") return 2; } try { closed = true; // boost::system::error_code ec; socket_->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); // socket_->shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec); socket_->close(ec); if (ec) log_(ERROR, "ec= " << ec) io_service_->stop(); // log_(INFO, "client= " << client_name << " closed.") return 0; } catch(std::exception& ex) { log_(ERROR, "Exception= " << ex.what() ) return 1; } }
int XORER::parallel_xor(int num_chunk, int chunk_size, void** chunk__, void* r_) { void** t_chunk__ = (void**)malloc(num_chunk*sizeof(void*) ); for (int i = 0; i < num_chunk; i++) t_chunk__[i] = chunk__[i]; // for (int i = 0; i < num_chunk; i++) // std::cout << "t_chunk_" << i << "= " << patch::arr_to_str<>(chunk_size, (char*)t_chunk__[i] ) << "\n"; char* t_r_ = static_cast<char*>(r_); std::vector<boost::shared_ptr<boost::thread> > thread_v; for (int i = 0; i < num_thread; i++) { int word_size = (i < num_thread - 1) ? (chunk_size / num_thread) : (chunk_size / num_thread) + chunk_size - num_thread*(chunk_size / num_thread); void** word__ = (void**)malloc(num_chunk*sizeof(void*) ); for (int c = 0; c < num_chunk; c++) word__[c] = t_chunk__[c]; log_(INFO, "thread_id= " << i << ", num_word= " << num_chunk << ", word_size= " << word_size) // boost::thread(&XORER::_xor, this, num_chunk, word_size, word__, t_r_); thread_v.push_back(boost::make_shared<boost::thread>(boost::bind(&XORER::_xor, this, num_chunk, word_size, word__, t_r_) ) ); if (i < num_thread - 1) { for (int c = 0; c < num_chunk; c++) t_chunk__[c] = static_cast<char*>(t_chunk__[c] ) + word_size; t_r_ += word_size; } } for (std::vector<boost::shared_ptr<boost::thread> >::iterator it = thread_v.begin(); it != thread_v.end(); it++) (*it)->join(); return 0; }
int XORER::_xor(int size_1, void*& _1_, int size_2, void*& _2_, void*& r_) { int size_diff = size_1 - size_2; if (size_diff != 0) { log_(WARNING, "size_diff= " << size_diff) } int size = size_1; if (size_diff > 0) { void* chunk_2_ = malloc(size_1*sizeof(char) ); memcpy(chunk_2_, _2_, size_2); memset(static_cast<char*>(chunk_2_) + size_2, 0, size_diff); free(_2_); _2_ = chunk_2_; } else if (size_diff < 0) { void* chunk_1_ = malloc(size_2*sizeof(char) ); memcpy(chunk_1_, _1_, size_1); memset(static_cast<char*>(chunk_1_) + size_1, 0, abs(size_diff) ); free(_1_); _1_ = chunk_1_; size = size_2; } char* chunk_1_ = static_cast<char*>(_1_); char* chunk_2_ = static_cast<char*>(_2_); char* t_r_ = static_cast<char*>(r_); // r_ = malloc(size*sizeof(char) ); for (int i = 0; i < size; i++) t_r_[i] = chunk_1_[i] ^ chunk_2_[i]; return 0; }
T VerboseValueStore::logValue(const char * func, const std::string & path, T && v, O o) const { std::string extra = ""; if(!std::is_same<bool, O>::value && o){ if(!vs_->hasKey(path)){ extra = "DEFAULT:"; } } log_(std::string(func) + "(\"" + path + "\")->" + extra + getValue(v)); return std::move(v); }
ComuactivClientSlot::ComuactivClientSlotImpl::ComuactivClientSlotImpl(std::string host, std::string highPort, pFlowTable table) : isStarted_(true), log_(std::string("ComuactivClientSlot#")), table_(table), host_(host), highPort_(highPort) { log_("created."); pthread_create(&tid, nullptr, &execute, this); }
static int dev_node_from_fd(int fd, unsigned int *maj, unsigned int *min) { struct stat buf; if (fstat(fd, &buf) < 0) { log_(_LOADER_WARNING, "MESA-LOADER: failed to stat fd %d\n", fd); return -1; } if (!S_ISCHR(buf.st_mode)) { log_(_LOADER_WARNING, "MESA-LOADER: fd %d not a character device\n", fd); return -1; } *maj = major(buf.st_rdev); *min = minor(buf.st_rdev); return 0; }
struct dht_val *insert_dht_val(char *key) { struct dht_val *r = (struct dht_val*) malloc(sizeof(struct dht_val)); if (r == NULL) { log_(WARN, "insert_dht_val() malloc error\n"); return(NULL); } memset(r, 0, sizeof(struct dht_val)); memcpy(r->key, key, sizeof(r->key)); r->next = dht_vals; dht_vals = r; return(r); }
void log(char *format, ...) { va_list ap; char str[255]; va_start(ap,format); // format string vsnprintf(str, 255, format, ap); // write it to log output log_(str); va_end(ap); }
void FHT::logSpectrum(float* out, float* p) { int n = num_ / 2, i, j, k, *r; if (log_vector_.size() < n) { log_vector_.resize(n); float f = n / log10(static_cast<double>(n)); for (i = 0, r = log_(); i < n; i++, r++) { j = static_cast<int>(rint(log10(i + 1.0) * f)); *r = j >= n ? n - 1 : j; } } semiLogSpectrum(p); *out++ = *p = *p / 100; for (k = i = 1, r = log_(); i < n; i++) { j = *r++; if (i == j) { *out++ = p[i]; } else { float base = p[k - 1]; float step = (p[j] - base) / (j - (k - 1)); for (float corr = 0; k <= j; k++, corr += step) *out++ = base + corr; } } }
int SDMClient::connect() { try { boost::asio::ip::tcp::resolver resolver(*io_service_); boost::asio::ip::tcp::resolver::query query(s_lip, boost::lexical_cast<std::string>(s_lport) ); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); log_(INFO, "client= " << client_name << " connecting to " << endpoint << "...") socket_->connect(endpoint); log_(INFO, "client= " << client_name << " connected.") return 0; } catch(std::exception& ex) { log_(ERROR, "Exception= " << ex.what() ) return 1; } }
void log_debug(const char* format, ...) { char buffer[1024]; va_list ap; if (_log_level > LOG_DEBUG) return; if (_log_file == NULL) _log_file = stderr; va_start(ap, format); vsnprintf(buffer, 1024, format, ap); buffer[1023] = 0; va_end(ap); log_(LOG_DEBUG, buffer); }
//TODO DOCUMENT THIS void cerr_log_throw(const std::string &msg, LogLevel level, const std::string &fileName, int lineNum) { std::string strerr = log_(msg, level, fileName, lineNum); if (level < THROW) { (*lf)(level, strerr); // log it now if not a throw return; } if (level < CRITICAL) throw (ErrorExcept(strerr.c_str())); else if (level < ASSERT_FAIL) throw (CriticalExcept(strerr.c_str())); else throw (AssertExcept(strerr.c_str())); }
static void log_packet(int line, char *pkt, int len) { if (!madns_log) return; int i; char buf[len * 3], *cp = buf; for (i = 12; i < len; ++i) cp += sprintf(cp, isgraph(pkt[i]) ? " %c" : " %02X", (uint8_t) pkt[i]); DNS_RESP *dp = (DNS_RESP *) pkt; log_(line, "UDP[%d]: tid=%hu flags=%hX nquer=%hu" " nansw=%hu nauth=%hu noth=%hu [%s ]\n", len, dp->tid, ntohs(dp->flags), ntohs(dp->nqueries), ntohs(dp->nanswers), ntohs(dp->nauth), ntohs(dp->nother), buf); }
void Connector::build_context(struct ibv_context* verb_) { if (s_ctx_ && s_ctx_->ctx_ != verb_) { log_(ERROR, "cannot handle events in more than one context.") exit(EXIT_FAILURE); } s_ctx_ = (struct context*)malloc(sizeof(struct context) ); s_ctx_->ctx_ = verb_; TEST_Z(s_ctx_->pd_ = ibv_alloc_pd(s_ctx_->ctx_) ); TEST_Z(s_ctx_->comp_channel_ = ibv_create_comp_channel(s_ctx_->ctx_) ); TEST_Z(s_ctx_->cq_ = ibv_create_cq(s_ctx_->ctx_, MAX_QP__CQ_LENGTH, NULL, s_ctx_->comp_channel_, 0) ); TEST_NZ(ibv_req_notify_cq(s_ctx_->cq_, 0) ) // TODO // TEST_NZ(pthread_create(pthread_v.back(), NULL, &Connector::bst_poll_cq, (void*)(this) ) ) pthread_v.push_back(new pthread_t() ); wrap_Connector* wrap_ = new wrap_Connector(this, s_ctx_); TEST_NZ(pthread_create(pthread_v.back(), NULL, call_poll_cq_w_wrap, wrap_) ) }
int hip_xmlrpc_rm(struct dht_val *v) { struct timeval now; struct sockaddr_storage server; int mode = XMLRPC_MODE_RM | XMLRPC_MODE_RETRY_OFF; int err, key_len, value_len, secret_len, rm_ttl; if (!v) { return(-1); } if (hip_dht_select_server(SA(&server)) < 0) { return(-1); } gettimeofday(&now, NULL); rm_ttl = TDIFF(v->expire_time, now); if (rm_ttl <= 0) { return(0); } key_len = sizeof(v->key); value_len = v->value_hash_len; secret_len = v->secret_len; err = hip_xmlrpc_getput(mode, v->app, SA(&server), (char *)v->key, key_len, (char *)v->value_hash, &value_len, (char *)v->secret, secret_len, rm_ttl); if (err == 0) { log_(NORM, "Removed a %s value from the DHT.\n", v->app); } return(err); }
static void * udev_dlopen_handle(void) { if (!udev_handle) { udev_handle = dlopen("libudev.so.1", RTLD_LOCAL | RTLD_LAZY); if (!udev_handle) { /* libudev.so.1 changed the return types of the two unref functions * from voids to pointers. We don't use those return values, and the * only ABI I've heard that cares about this kind of change (calling * a function with a void * return that actually only returns void) * might be ia64. */ udev_handle = dlopen("libudev.so.0", RTLD_LOCAL | RTLD_LAZY); if (!udev_handle) { log_(_LOADER_WARNING, "Couldn't dlopen libudev.so.1 or " "libudev.so.0, driver detection may be broken.\n"); } } } return udev_handle; }
std::vector<KeyValueStorePair> VerboseValueStore::getChildren() const { log_(std::string(__func__) + "()"); return vs_->getChildren(); //TODO instrument with VerboseValueStore, too. }
KeyValueStorePair VerboseValueStore::getChild(const std::string & key) const { log_(std::string(__func__) + "(" + key + ")"); auto log = log_; return KeyValueStorePair(key, std::make_shared<VerboseValueStore>(vs_->getChild(key), [log, key](const std::string &text){ log("child(" + key + "):" + text);})); }
ComuactivClientSlot::ComuactivClientSlotImpl::~ComuactivClientSlotImpl() { pthread_join(tid, nullptr); log_("thread joined."); }
/* * \fn hip_xmlrpc_getput() * * \param mode determines get or put, app, retry on/off * If retry is off only one attempt should be made, * on means the connect() should keep retrying * \param app string to use in the XML RPC application field * \param server server address and port to connect to * \param key DHT key used for get or put * \param key_len length of DHT key in bytes * \param value DHT value used for put, ptr for storing value for get * \param value_len ptr to length of value buffer, length of get is returned * \param secret secret value used to make put removable * \param secret_len length of secret value * \param ttl time to live in seconds * * \brief Perform the XML RPC GET, PUT, and RM operations. */ int hip_xmlrpc_getput(int mode, char *app, struct sockaddr *server, char *key, int key_len, char *value, int *value_len, char *secret, int secret_len, int ttl) { xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL, node; int len = 0, s, retval = 0; char buff[2048], oper[14]; unsigned char key64[2 * DHT_KEY_SIZE], val64[2 * DHT_VAL_SIZE]; unsigned char tmp[2 * DHT_VAL_SIZE], *xmlbuff = NULL; fd_set read_fdset; struct timeval timeout, now; char *p; unsigned int retry_attempts = 0; struct sockaddr_in src_addr; struct dht_val *dv, rm; SHA_CTX c; __u8 secret_hash[SHA_DIGEST_LENGTH], value_hash[SHA_DIGEST_LENGTH]; int rm_ttl = 0, value_hash_len; int retry = ((mode & 0x00F0) == XMLRPC_MODE_RETRY_ON); if ((key_len > (2 * DHT_KEY_SIZE)) || (*value_len > (2 * DHT_VAL_SIZE))) { return(-1); } /* * support for removable puts */ memset(&rm, 0, sizeof(struct dht_val)); if ((mode & 0x000F) == XMLRPC_MODE_PUT) { /* * produce hashes of the secret and the value, for later removal */ SHA1_Init(&c); SHA1_Update(&c, value, *value_len); SHA1_Final(value_hash, &c); SHA1_Init(&c); SHA1_Update(&c, secret, secret_len); SHA1_Final(secret_hash, &c); /* * check if we already published a record with this key; record * this new secret value and value_hash */ pthread_mutex_lock(&dht_vals_lock); gettimeofday(&now, NULL); dv = lookup_dht_val(key); if (dv) { /* save old secret so we can remove it later below */ memcpy(&rm, &dv, sizeof(struct dht_val)); /* any time left for removing the old record? */ rm_ttl = TDIFF(rm.expire_time, now); } else { dv = insert_dht_val(key); } strncpy(dv->app, app, sizeof(dv->app)); dv->value_hash_len = SHA_DIGEST_LENGTH; memcpy(dv->value_hash, value_hash, SHA_DIGEST_LENGTH); dv->secret_len = secret_len; memcpy(dv->secret, secret, secret_len); dv->expire_time.tv_usec = now.tv_usec; dv->expire_time.tv_sec = now.tv_sec + ttl; pthread_mutex_unlock(&dht_vals_lock); } switch (mode & 0x000F) { case XMLRPC_MODE_PUT: sprintf(oper, "put_removable"); break; case XMLRPC_MODE_GET: sprintf(oper, "get"); break; case XMLRPC_MODE_RM: sprintf(oper, "rm"); break; default: log_(WARN, "Invalid XMLRPC mode given to DHT.\n"); return(-1); } /* * create a new XML document */ doc = xmlNewDoc(BAD_CAST "1.0"); root_node = xmlNewNode(NULL, BAD_CAST "methodCall"); xmlDocSetRootElement(doc, root_node); node = xmlNewChild(root_node, NULL, BAD_CAST "methodName", BAD_CAST oper); node = xmlNewChild(root_node, NULL, BAD_CAST "params", NULL); memset(tmp, 0, sizeof(tmp)); memcpy(tmp, key, key_len); EVP_EncodeBlock(key64, tmp, key_len); xml_new_param(node, "base64", (char *)key64); /* key */ /* log_(NORM, "Doing %s using key(%d)=", * ((mode & 0x000F)==XMLRPC_MODE_PUT) ? "PUT":"GET", key_len); * print_hex(key, key_len); * log_(NORM, " [%s]\n", key64); // */ switch (mode & 0x000F) { case XMLRPC_MODE_PUT: memset(tmp, 0, sizeof(tmp)); memcpy(tmp, value, *value_len); EVP_EncodeBlock(val64, tmp, *value_len); xml_new_param(node, "base64", (char *)val64); /* value */ xml_new_param(node, "string", "SHA"); /* hash type */ memset(tmp, 0, sizeof(tmp)); memcpy(tmp, secret_hash, SHA_DIGEST_LENGTH); EVP_EncodeBlock(val64, tmp, SHA_DIGEST_LENGTH); xml_new_param(node, "base64", (char *)val64); /* secret_hash */ sprintf((char *)tmp, "%d", ttl); xml_new_param(node, "int", (char *)tmp); /* lifetime */ break; case XMLRPC_MODE_GET: xml_new_param(node, "int", "10"); /* maxvals */ xml_new_param(node, "base64", ""); /* placemark */ memset(value, 0, *value_len); break; case XMLRPC_MODE_RM: memset(tmp, 0, sizeof(tmp)); memcpy(tmp, value_hash, SHA_DIGEST_LENGTH); EVP_EncodeBlock(val64, tmp, SHA_DIGEST_LENGTH); xml_new_param(node, "base64", (char *)val64); /* value_hash */ xml_new_param(node, "string", "SHA"); /* hash type */ memset(tmp, 0, sizeof(tmp)); memcpy(tmp, secret, secret_len); EVP_EncodeBlock(val64, tmp, secret_len); xml_new_param(node, "base64", (char *)val64); /* secret */ sprintf((char *)tmp, "%d", ttl); xml_new_param(node, "int", (char *)tmp); /* lifetime */ } xml_new_param(node, "string", app); /* app */ xmlDocDumpFormatMemory(doc, &xmlbuff, &len, 0); /* * Build an HTTP POST and transmit to server */ memset(buff, 0, sizeof(buff)); build_http_post_header(buff, len, server); /* len is XML length above */ memcpy(&buff[strlen(buff)], xmlbuff, len); xmlFree(xmlbuff); len = strlen(buff) + 1; connect_retry: /* Connect and send the XML RPC */ if ((s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { log_(WARN, "DHT connect - socket error: %s\n", strerror(errno)); retval = -1; goto putget_exit; } /* Use the preferred address as source */ memset(&src_addr, 0, sizeof(src_addr)); src_addr.sin_family = AF_INET; src_addr.sin_addr.s_addr = get_preferred_addr(); if (!src_addr.sin_addr.s_addr) { log_(NORM, "No preferred address, deferring DHT!\n"); return(-1); } log_(NORM, "Using source address of %s for DHT %s.\n", logaddr(SA(&src_addr)), oper); fflush(stdout); if (bind(s, SA(&src_addr), SALEN(&src_addr)) < 0) { log_(WARN, "DHT connect - bind error: %s\n", strerror(errno)); } if (g_state != 0) { return(-1); } if (retry && (retry_attempts > 0)) { /* quit after a certain number of retries */ if (retry_attempts >= HCNF.max_retries) { retval = -2; goto putget_exit; } /* wait packet_timeout seconds before retrying */ hip_sleep(HCNF.packet_timeout); } retry_attempts++; if (connect(s, server, SALEN(server)) < 0) { log_(WARN, "DHT server connect error: %s\n", strerror(errno)); closesocket(s); #ifdef __WIN32__ errno = WSAGetLastError(); if (retry && ((errno == WSAETIMEDOUT) || (errno == WSAENETUNREACH))) { goto connect_retry; } #else if (retry && ((errno == ETIMEDOUT) || (errno == EHOSTUNREACH))) { goto connect_retry; } #endif retval = -3; goto putget_exit; } if (send(s, buff, len, 0) != len) { log_(WARN, "DHT sent incorrect number of bytes\n"); retval = -4; goto putget_exit; } xmlFreeDoc(doc); doc = NULL; /* * Receive XML RPC response from server */ FD_ZERO(&read_fdset); FD_SET((unsigned int)s, &read_fdset); /* use longer timeout when retry==TRUE, because we have own thread */ if (retry) { timeout.tv_sec = 3; timeout.tv_usec = 0; } else { timeout.tv_sec = 0; timeout.tv_usec = 300000; /* 300ms */ } if (select(s + 1, &read_fdset, NULL, NULL, &timeout) < 0) { log_(WARN, "DHT select error: %s\n", strerror(errno)); retval = -5; goto putget_exit; } else if (FD_ISSET(s, &read_fdset)) { if ((len = recv(s, buff, sizeof(buff) - 1, 0)) <= 0) { log_(WARN, "DHT error receiving from server: %s\n", strerror(errno)); retval = -6; goto putget_exit; } if (strncmp(buff, "HTTP", 4) != 0) { return(-7); } if ((p = strstr(buff, "Content-Length: ")) == NULL) { return(-8); } else /* advance ptr to Content-Length */ { p += 16; } sscanf(p, "%d", &len); p = strchr(p, '\n') + 3; /* advance to end of line */ retval = hip_xmlrpc_parse_response(mode, p, len, value, value_len); log_(NORM, "DHT server responded with return code %d (%s).\n", retval, hip_xmlrpc_resp_to_str(retval)); } else { /* select timeout */ if (retry) /* XXX testme: retry select instead? */ { goto connect_retry; } retval = -9; } putget_exit: #ifdef __WIN32__ closesocket(s); #else close(s); #endif if (doc != NULL) { xmlFreeDoc(doc); } if (rm_ttl > 0) { value_hash_len = sizeof(rm.value_hash); hip_xmlrpc_getput(((mode & 0x00F0) | XMLRPC_MODE_RM), app, server, key, key_len, (char *)rm.value_hash, &value_hash_len, (char *)rm.secret, secret_len, rm_ttl); } return(retval); }
static int drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id) { drmVersionPtr version; *chip_id = -1; version = drmGetVersion(fd); if (!version) { log_(_LOADER_WARNING, "MESA-LOADER: invalid drm fd\n"); return 0; } if (!version->name) { log_(_LOADER_WARNING, "MESA-LOADER: unable to determine the driver name\n"); drmFreeVersion(version); return 0; } if (strcmp(version->name, "i915") == 0) { struct drm_i915_getparam gp; int ret; *vendor_id = 0x8086; memset(&gp, 0, sizeof(gp)); gp.param = I915_PARAM_CHIPSET_ID; gp.value = chip_id; ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); if (ret) { log_(_LOADER_WARNING, "MESA-LOADER: failed to get param for i915\n"); *chip_id = -1; } } else if (strcmp(version->name, "radeon") == 0) { struct drm_radeon_info info; int ret; *vendor_id = 0x1002; memset(&info, 0, sizeof(info)); info.request = RADEON_INFO_DEVICE_ID; info.value = (unsigned long) chip_id; ret = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); if (ret) { log_(_LOADER_WARNING, "MESA-LOADER: failed to get info for radeon\n"); *chip_id = -1; } } else if (strcmp(version->name, "nouveau") == 0) { *vendor_id = 0x10de; /* not used */ *chip_id = 0; } else if (strcmp(version->name, "vmwgfx") == 0) { *vendor_id = 0x15ad; /* assume SVGA II */ *chip_id = 0x0405; } drmFreeVersion(version); return (*chip_id >= 0); }