int main(int argc, char **argv) { dump_link_map(stdout); printsymbol(printf); printsymbol(malloc); printsymbol(dlsym); struct link_map *map = get_module_by_full_path("/lib64/libdl.so.2"); if (map) { printf("%s\n", map->l_name); } else { printf("not found.\n"); } }
void set_link_params(int l_index, int blackhole, int p_which) { /* Grab the pipe params from the link_map table and then set them into dummynet by calling setsockopt */ int p_index; for (p_index = 0; p_index < link_map[l_index].numpipes; p_index++) { /* * Want to do all the pipes, or just the one pipe that was * specified. */ if(p_which == -1 || p_which == p_index) { struct dn_pipe pipe; /* get the params stored in the link table*/ structpipe_params *p_params = &(link_map[l_index].params[p_index]); if (debug) info("entered the loop, pindex=%d, pipe=%d\n", p_index, link_map[l_index].pipes[p_index]); memset(&pipe, 0, sizeof pipe); /* set the bandwidth and delay*/ pipe.bandwidth = p_params->bw; pipe.delay = p_params->delay; /* pramod-CHANGES */ pipe.backfill = p_params->backfill; info("entered the loop, pindex=%d, pipe=%d, bw=%d, delay=%d, backfill=%d\n", p_index, link_map[l_index].pipes[p_index], pipe.bandwidth, pipe.delay, pipe.backfill); dump_link_map(); /* set the pipe number*/ pipe.pipe_nr = link_map[l_index].pipes[p_index]; /* if we want to blackhole (in the case of EVENT_DOWN, then we set all other pipe params same, but change the plr to 1.0 */ { double d = p_params->plr; if (blackhole) d = 1.0; pipe.fs.plr = (int)(d*0x7fffffff); } /* set the queue size*/ pipe.fs.qsize = p_params->q_size; /* set the number of buckets used for dynamic queues*/ pipe.fs.rq_size = p_params->buckets; #if 0 pipe.fs.rq_elements = num_qs; #endif /* initialise pipe flags to zero */ pipe.fs.flags_fs = 0; /* set if the q size is in slots or in bytes*/ if(p_params->flags_p & PIPE_QSIZE_IN_BYTES) pipe.fs.flags_fs |= DN_QSIZE_IS_BYTES; #if 0 pipe.fs.flow_mask.proto = 0; pipe.fs.flow_mask.src_ip = 0; pipe.fs.flow_mask.dst_ip = 0; pipe.fs.flow_mask.src_port = 0; pipe.fs.flow_mask.dst_port = 0; #endif /* set if the pipe has a flow mask*/ if(p_params->flags_p & PIPE_HAS_FLOW_MASK){ pipe.fs.flags_fs |= DN_HAVE_FLOW_MASK; pipe.fs.flow_mask.proto = p_params->id.proto; pipe.fs.flow_mask.src_ip = p_params->id.src_ip; pipe.fs.flow_mask.dst_ip = p_params->id.dst_ip; pipe.fs.flow_mask.src_port = p_params->id.src_port; pipe.fs.flow_mask.dst_port = p_params->id.dst_port; } /* set the queing discipline and other relevant params*/ if(p_params->flags_p & (PIPE_Q_IS_GRED | PIPE_Q_IS_RED)){ /* set GRED params */ pipe.fs.flags_fs |= DN_IS_RED; pipe.fs.max_th = p_params->red_gred_params.max_th; pipe.fs.min_th = p_params->red_gred_params.min_th; pipe.fs.w_q = (int) ( p_params->red_gred_params.w_q * (1 << SCALE_RED) ) ; pipe.fs.max_p = (int) ( p_params->red_gred_params.max_p * (1 << SCALE_RED) ); if(p_params->flags_p & PIPE_Q_IS_GRED) pipe.fs.flags_fs |= DN_IS_GENTLE_RED; if(pipe.bandwidth){ size_t len ; int lookup_depth, avg_pkt_size ; double s, idle, weight, w_q ; struct clockinfo clock ; int t ; len = sizeof(int) ; if (sysctlbyname("net.inet.ip.dummynet.red_lookup_depth", &lookup_depth, &len, NULL, 0) == -1){ error("cant get net.inet.ip.dummynet.red_lookup_depth"); return; } if (lookup_depth == 0) { info("net.inet.ip.dummynet.red_lookup_depth must" "greater than zero") ; return; } len = sizeof(int) ; if (sysctlbyname("net.inet.ip.dummynet.red_avg_pkt_size", &avg_pkt_size, &len, NULL, 0) == -1){ error("cant get net.inet.ip.dummynet.red_avg_pkt_size"); return; } if (avg_pkt_size == 0){ info("net.inet.ip.dummynet.red_avg_pkt_size must" "greater than zero") ; return; } len = sizeof(struct clockinfo) ; if (sysctlbyname("kern.clockrate", &clock, &len, NULL, 0) == -1) { error("cant get kern.clockrate") ; return; } /* ticks needed for sending a medium-sized packet */ s = clock.hz * avg_pkt_size * 8 / pipe.bandwidth; /* * max idle time (in ticks) before avg queue size becomes 0. * NOTA: (3/w_q) is approx the value x so that * (1-w_q)^x < 10^-3. */ w_q = ((double) pipe.fs.w_q) / (1 << SCALE_RED) ; idle = s * 3. / w_q ; pipe.fs.lookup_step = (int) idle / lookup_depth ; if (!pipe.fs.lookup_step) pipe.fs.lookup_step = 1 ; weight = 1 - w_q ; for ( t = pipe.fs.lookup_step ; t > 0 ; --t ) weight *= weight ; pipe.fs.lookup_weight = (int) (weight * (1 << SCALE_RED)) ; } } /* else DROPTAIL*/ info("backfill before configure for pipe=%d, backfill=%d\n",pipe.pipe_nr, pipe.backfill); /* now call setsockopt*/ if (setsockopt(s_dummy,IPPROTO_IP, IP_DUMMYNET_CONFIGURE, &pipe,sizeof pipe) < 0) error("IP_DUMMYNET_CONFIGURE setsockopt failed\n"); } } }