00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include "../../str.h"
00033 #include "../../dprint.h"
00034 #include "../../rpc.h"
00035 #include "tree.h"
00036 #include "pr.h"
00037
00038
00039 static const char *rpc_dump_doc[2] = {"Dump the prefix route tree", NULL};
00040 static const char *rpc_reload_doc[2] = {"Reload prefix routes from DB", NULL};
00041
00042
00046 static void rpc_dump(rpc_t *rpc, void *c)
00047 {
00048 char buf[1024];
00049 FILE *f;
00050
00051 f = tmpfile();
00052 if (!f) {
00053 rpc->fault(c, 500, "failed to open temp file");
00054 return;
00055 }
00056
00057 tree_print(f);
00058
00059 rewind(f);
00060
00061 while (!feof(f)) {
00062
00063 if (!fgets(buf, sizeof(buf), f))
00064 break;
00065
00066 buf[strlen(buf)-1] = '\0';
00067
00068 rpc->printf(c, "%s", buf);
00069 }
00070
00071 fclose(f);
00072 }
00073
00074
00078 static void rpc_reload(rpc_t *rpc, void *c)
00079 {
00080 LOG(L_NOTICE, "prefix_route: Reloading prefix route tree from DB\n");
00081
00082 if (0 != pr_db_load()) {
00083 LOG(L_ERR, "prefix_route: rpc_reload(): db_load() failed\n");
00084 rpc->fault(c, 400, "failed to reload prefix routes");
00085 }
00086 else {
00087 rpc->printf(c, "Prefix routes reloaded successfully");
00088 }
00089 }
00090
00091
00092 rpc_export_t pr_rpc[] = {
00093 {"prefix_route.reload", rpc_reload, rpc_reload_doc, 0},
00094 {"prefix_route.dump", rpc_dump, rpc_dump_doc, 0},
00095 {0, 0, 0, 0}
00096 };