[Linux-decnet-commit] CVS: dnprogs/nml nml.c,1.3,1.4
Brought to you by:
chrissie_c,
ph3-der-loewe
From: Christine C. <chr...@us...> - 2008-09-06 12:34:39
|
Update of /cvsroot/linux-decnet/dnprogs/nml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7994 Modified Files: nml.c Log Message: 'SHOW KNOWN NODES' now also shows reachability state Index: nml.c =================================================================== RCS file: /cvsroot/linux-decnet/dnprogs/nml/nml.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** nml.c 4 Sep 2008 15:25:38 -0000 1.3 --- nml.c 6 Sep 2008 12:34:34 -0000 1.4 *************** *** 48,55 **** --- 48,61 ---- #define NODESTATE_UNREACHABLE 5 + typedef int (*neigh_fn_t)(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); + static struct rtnl_handle talk_rth; static struct rtnl_handle listen_rth; static int first_time = 1; + #define MAX_ADJACENT_NODES 1024 + static int num_adj_nodes = 0; + static unsigned short adj_node[MAX_ADJACENT_NODES]; + static void makeupper(char *s) { *************** *** 58,61 **** --- 64,78 ---- } + static int adjacent_node(struct nodeent *n) + { + int i; + unsigned short nodeid = n->n_addr[0] | n->n_addr[1]<<8; + + for (i=0; i<num_adj_nodes; i++) + if (adj_node[i] == nodeid) + return 1; + + return 0; + } static char *if_index_to_name(int ifindex) *************** *** 150,155 **** } ! /* Called for each neighbour node in the list */ ! static int got_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { struct ndmsg *r = NLMSG_DATA(n); --- 167,194 ---- } ! /* Save a neighbour entry in a list so we can check it when doing the ! KNOWN NODES display ! */ ! static int save_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ! { ! struct ndmsg *r = NLMSG_DATA(n); ! struct rtattr * tb[NDA_MAX+1]; ! int sock = (int)arg; ! ! memset(tb, 0, sizeof(tb)); ! parse_rtattr(tb, NDA_MAX, NDA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof ! (*r))); ! ! if (tb[NDA_DST]) ! { ! unsigned char *addr = RTA_DATA(tb[NDA_DST]); ! if (++num_adj_nodes < MAX_ADJACENT_NODES) ! adj_node[num_adj_nodes] = addr[0] | (addr[1]<<8); ! } ! return 0; ! } ! ! /* Called for each neighbour node in the list - send it to the socket */ ! static int send_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { struct ndmsg *r = NLMSG_DATA(n); *************** *** 188,192 **** /* SHOW ADJACENT NODES */ ! static int send_neighbour_nodes(int sock) { if (first_time) --- 227,231 ---- /* SHOW ADJACENT NODES */ ! static int get_neighbour_nodes(int sock, neigh_fn_t neigh_fn) { if (first_time) *************** *** 206,219 **** /* Calls got_neigh() for each adjacent node */ ! if (rtnl_dump_filter(&listen_rth, got_neigh, (void *)sock, NULL, NULL) < 0) { syslog(LOG_ERR, "Dump terminated: %m\n"); return -1; } ! dnetlog(LOG_DEBUG, "end of send_neighbour_nodes\n"); return 0; } /* SHOW/LIST KNOWN NODES */ ! static int send_perm_nodes(int sock) { void *nodelist; --- 245,258 ---- /* Calls got_neigh() for each adjacent node */ ! if (rtnl_dump_filter(&listen_rth, neigh_fn, (void *)sock, NULL, NULL) < 0) { syslog(LOG_ERR, "Dump terminated: %m\n"); return -1; } ! dnetlog(LOG_DEBUG, "end of get_neighbour_nodes\n"); return 0; } /* SHOW/LIST KNOWN NODES */ ! static int send_all_nodes(int sock, unsigned char perm_only) { void *nodelist; *************** *** 222,225 **** --- 261,269 ---- send_exec(sock); + /* Get adjacent nodes */ + num_adj_nodes = 0; + if (!perm_only) + get_neighbour_nodes(sock, save_neigh); + /* Now iterate the permanent database */ nodelist = dnet_getnode(); *************** *** 228,232 **** { struct nodeent *n = getnodebyname(nodename); ! send_node(sock, n, 0, NULL, NODESTATE_UNKNOWN); nodename = dnet_nextnode(nodelist); } --- 272,277 ---- { struct nodeent *n = getnodebyname(nodename); ! ! send_node(sock, n, 0, NULL, adjacent_node(n)?NODESTATE_REACHABLE:NODESTATE_UNKNOWN); nodename = dnet_nextnode(nodelist); } *************** *** 254,258 **** dnetlog(LOG_DEBUG, "option=%d. entity=%d\n", option, entity); ! switch (option) { case 0: // nodes summary --- 299,303 ---- dnetlog(LOG_DEBUG, "option=%d. entity=%d\n", option, entity); ! switch (option & 0x7f) { case 0: // nodes summary *************** *** 260,268 **** case 32: // nodes state if (entity == 0xff) ! send_perm_nodes(sock); if (entity == 0xfc) ! send_neighbour_nodes(sock); if (entity == 0x00) ! send_exec(sock); // TODO not quite right. break; default: --- 305,313 ---- case 32: // nodes state if (entity == 0xff) ! send_all_nodes(sock, option & 0x80); if (entity == 0xfc) ! get_neighbour_nodes(sock, send_neigh); if (entity == 0x00) ! send_exec(sock); break; default: |