blob: 41ed4c76977a37fdac5ca015c425378d6574e01a [file] [log] [blame]
Alexander Afanasyev6df5ad92012-10-09 10:21:50 -07001diff --git csrc/libexec/ccndc-srv.c csrc/libexec/ccndc-srv.c
2index f6af4ee..a2483a1 100644
3--- csrc/libexec/ccndc-srv.c
4+++ csrc/libexec/ccndc-srv.c
5@@ -188,10 +188,10 @@ ccndc_query_srv(const unsigned char *domain, int domain_size,
6
7 if (hostp) {
8 size = strlen(host);
9- *hostp = calloc(1, size);
10+ *hostp = calloc(1, size+1);
11 if (!*hostp)
12 return (-1);
13- strncpy(*hostp, host, size);
14+ strncpy(*hostp, host, size+1);
15 }
16 if (portp) {
17 *portp = port;
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070018diff --git csrc/libexec/ccndc.c csrc/libexec/ccndc.c
Alexander Afanasyev6df5ad92012-10-09 10:21:50 -070019index ecde5f0..76102ed 100644
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070020--- csrc/libexec/ccndc.c
21+++ csrc/libexec/ccndc.c
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070022@@ -580,9 +580,11 @@ ccndc_srv(struct ccndc_data *self,
23 int port = 0;
24 char port_str[10];
25 struct ccn_charbuf *uri;
26+ struct ccn_charbuf *uri_auto;
27 struct ccn_face_instance *face;
28 struct ccn_face_instance *newface;
29 struct ccn_forwarding_entry *prefix;
30+ struct ccn_forwarding_entry *prefix_auto;
31 int res;
32
33 res = ccndc_query_srv(domain, domain_size, &host, &port, &proto);
34@@ -649,12 +651,29 @@ ccndc_srv(struct ccndc_data *self,
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070035 if (res < 0) {
36 ccndc_warn(__LINE__, "Cannot register prefix [%s]\n", ccn_charbuf_as_string(uri));
37 }
38+
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070039+ uri_auto = ccn_charbuf_create();
40+ ccn_charbuf_append_string(uri_auto, "ccnx:/autoconf-route");
41+ prefix_auto = parse_ccn_forwarding_entry(self, ccn_charbuf_as_string(uri_auto), NULL,
42+ self->lifetime);
43+ if (prefix_auto == NULL) {
44+ res = -1;
45+ goto Cleanup;
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070046+ }
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070047+
48+ prefix_auto->faceid = prefix->faceid;
49+ res = ccndc_do_prefix_action(self, "prefixreg", prefix_auto);
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070050+ if (res < 0) {
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070051+ ccndc_warn(__LINE__, "Cannot register prefix_auto [%s]\n", ccn_charbuf_as_string(uri_auto));
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070052+ }
53
54 Cleanup:
Alexander Afanasyev6df5ad92012-10-09 10:21:50 -070055- free(uri);
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070056 free(host);
Alexander Afanasyev6df5ad92012-10-09 10:21:50 -070057+ ccn_charbuf_destroy(&uri);
58+ ccn_charbuf_destroy(&uri_auto);
Alexander Afanasyevf22a6652012-10-05 09:30:15 -070059 ccn_face_instance_destroy(&face);
60 ccn_forwarding_entry_destroy(&prefix);
61+ ccn_forwarding_entry_destroy(&prefix_auto);
62 return res;
63 }
64
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070065diff --git csrc/util/ccnd-autoconfig.sh csrc/util/ccnd-autoconfig.sh
66new file mode 100755
Alexander Afanasyev92828362012-10-08 11:24:32 -070067index 0000000..48ec9fc
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070068--- /dev/null
69+++ csrc/util/ccnd-autoconfig.sh
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070070@@ -0,0 +1,55 @@
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -070071+# Source file: util/ccnd-autoconfig.sh
72+#
73+# Script that tries to (automatically) discover of a local ccnd gateway
74+#
75+# Part of the CCNx distribution.
76+#
77+# Copyright (C) 2012 Palo Alto Research Center, Inc.
78+#
79+# This work is free software; you can redistribute it and/or modify it under
80+# the terms of the GNU General Public License version 2 as published by the
81+# Free Software Foundation.
82+# This work is distributed in the hope that it will be useful, but WITHOUT ANY
83+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
84+# FOR A PARTICULAR PURPOSE.
85+
86+# This script should be installed in the same place as ccnd, ccndc, ccndsmoketest, ...
87+# adjust the path to get consistency.
88+D=`dirname "$0"`
89+export PATH="$D:$PATH"
90+
Alexander Afanasyeve985adc2012-10-05 09:18:23 -070091+ccndstatus | grep 224.0.23.170:59695 > /dev/null
92+MCAST_EXISTED=$?
93+
94+# Removing any previously created (either by this script or ccndc srv command) default route
95+for i in `ccndstatus | grep "ccnx:/autoconf-route face" | awk '{print $3}'`; do
96+ ccndc del / face $i
97+ ccndc del /autoconf-route face $i
98+done
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -070099+
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -0700100+# Set temporary multicast face
101+ccndc -t 10 add "/local/ndn" udp 224.0.23.170 59695
102+
103+# Get info from local hub, if available
104+info=`ccncat -s 2 /local/ndn/udp`
105+if [ "x$info" = "x" ]; then
106+ echo "Local hub is not availble, trying to use DNS to get local configuration"
107+ # Try to use DNS search list to get default route information
108+ ccndc srv
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700109+
Alexander Afanasyev92828362012-10-08 11:24:32 -0700110+ if [ $MCAST_EXISTED -eq 1 ]; then
Alexander Afanasyeve985adc2012-10-05 09:18:23 -0700111+ # destroying multicast face
112+ ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face
113+ fi
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -0700114+ exit 1
115+fi
116+
117+echo Setting default route to a local hub: "$info"
118+echo "$info" | xargs ccndc add / udp
Alexander Afanasyeve985adc2012-10-05 09:18:23 -0700119+echo "$info" | xargs ccndc add /autoconf-route udp
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700120+
Alexander Afanasyev92828362012-10-08 11:24:32 -0700121+if [ $MCAST_EXISTED -eq 1 ]; then
Alexander Afanasyeve985adc2012-10-05 09:18:23 -0700122+ # destroying multicast face
123+ ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face
124+fi
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700125+
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -0700126diff --git csrc/util/ccnd-publish-local-info.sh csrc/util/ccnd-publish-local-info.sh
127new file mode 100755
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700128index 0000000..b433f69
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -0700129--- /dev/null
130+++ csrc/util/ccnd-publish-local-info.sh
131@@ -0,0 +1,34 @@
132+# Source file: util/ccnd-autoconfig.sh
133+#
134+# Script to publish information about local ccnd gateway in local repo (should be run only on ccnd gateway nodes)
135+#
136+# Part of the CCNx distribution.
137+#
138+# Copyright (C) 2012 Palo Alto Research Center, Inc.
139+#
140+# This work is free software; you can redistribute it and/or modify it under
141+# the terms of the GNU General Public License version 2 as published by the
142+# Free Software Foundation.
143+# This work is distributed in the hope that it will be useful, but WITHOUT ANY
144+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
145+# FOR A PARTICULAR PURPOSE.
146+
147+# This script should be installed in the same place as ccnd, ccndc, ccndsmoketest, ...
148+# adjust the path to get consistency.
149+D=`dirname "$0"`
150+export PATH="$D:$PATH"
151+
152+#
153+
154+udp_face_info=$1
155+local_prefix=$2
156+
157+if [ "x$udp_face_info" = "x" -o "x$local_prefix" = "x" ]; then
158+ echo "Usage: "
159+ echo " " $0 " <udp_face_info> <routable_prefix>"
160+ exit 1
161+fi
162+
Alexander Afanasyev72af1bf2012-10-04 12:14:10 -0700163+echo $udp_face_info | ccnseqwriter -c 1 -r -x 5 "/local/ndn/udp"
164+echo $local_prefix | ccnseqwriter -c 1 -r -x 5 "/local/ndn/prefix"
Alexander Afanasyeva556d7e2012-10-03 17:35:08 -0700165+
166diff --git csrc/util/dir.mk csrc/util/dir.mk
167index f29038f..94bc7b6 100644
168--- csrc/util/dir.mk
169+++ csrc/util/dir.mk
170@@ -14,8 +14,10 @@
171
172 SCRIPTSRC = shebang \
173 ccndstart.sh ccndstop.sh ccndstatus.sh ccndlogging.sh ccnget.sh ccnput.sh \
174- ccntestloop-trampoline
175-PROGRAMS = ccndstart ccndstop ccndstatus ccntestloop ccndlogging ccnget ccnput
176+ ccntestloop-trampoline \
177+ ccnd-autoconfig.sh ccnd-publish-local-info.sh
178+
179+PROGRAMS = ccndstart ccndstop ccndstatus ccntestloop ccndlogging ccnget ccnput ccnd-autoconfig ccnd-publish-local-info
180 INSTALLED_PROGRAMS = $(PROGRAMS)
181
182 default all: $(SCRIPTSRC) $(PROGRAMS)