Alexander Afanasyev | 6df5ad9 | 2012-10-09 10:21:50 -0700 | [diff] [blame] | 1 | diff --git csrc/libexec/ccndc-srv.c csrc/libexec/ccndc-srv.c |
| 2 | index 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 Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 18 | diff --git csrc/libexec/ccndc.c csrc/libexec/ccndc.c |
Alexander Afanasyev | 6df5ad9 | 2012-10-09 10:21:50 -0700 | [diff] [blame] | 19 | index ecde5f0..76102ed 100644 |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 20 | --- csrc/libexec/ccndc.c |
| 21 | +++ csrc/libexec/ccndc.c |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 22 | @@ -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 Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 35 | if (res < 0) { |
| 36 | ccndc_warn(__LINE__, "Cannot register prefix [%s]\n", ccn_charbuf_as_string(uri)); |
| 37 | } |
| 38 | + |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 39 | + 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 Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 46 | + } |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 47 | + |
| 48 | + prefix_auto->faceid = prefix->faceid; |
| 49 | + res = ccndc_do_prefix_action(self, "prefixreg", prefix_auto); |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 50 | + if (res < 0) { |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 51 | + ccndc_warn(__LINE__, "Cannot register prefix_auto [%s]\n", ccn_charbuf_as_string(uri_auto)); |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 52 | + } |
| 53 | |
| 54 | Cleanup: |
Alexander Afanasyev | 6df5ad9 | 2012-10-09 10:21:50 -0700 | [diff] [blame] | 55 | - free(uri); |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 56 | free(host); |
Alexander Afanasyev | 6df5ad9 | 2012-10-09 10:21:50 -0700 | [diff] [blame] | 57 | + ccn_charbuf_destroy(&uri); |
| 58 | + ccn_charbuf_destroy(&uri_auto); |
Alexander Afanasyev | f22a665 | 2012-10-05 09:30:15 -0700 | [diff] [blame] | 59 | ccn_face_instance_destroy(&face); |
| 60 | ccn_forwarding_entry_destroy(&prefix); |
| 61 | + ccn_forwarding_entry_destroy(&prefix_auto); |
| 62 | return res; |
| 63 | } |
| 64 | |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 65 | diff --git csrc/util/ccnd-autoconfig.sh csrc/util/ccnd-autoconfig.sh |
| 66 | new file mode 100755 |
Alexander Afanasyev | 9282836 | 2012-10-08 11:24:32 -0700 | [diff] [blame] | 67 | index 0000000..48ec9fc |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 68 | --- /dev/null |
| 69 | +++ csrc/util/ccnd-autoconfig.sh |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 70 | @@ -0,0 +1,55 @@ |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 71 | +# 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 Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 91 | +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 Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 99 | + |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 100 | +# 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 Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 109 | + |
Alexander Afanasyev | 9282836 | 2012-10-08 11:24:32 -0700 | [diff] [blame] | 110 | + if [ $MCAST_EXISTED -eq 1 ]; then |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 111 | + # destroying multicast face |
| 112 | + ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face |
| 113 | + fi |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 114 | + exit 1 |
| 115 | +fi |
| 116 | + |
| 117 | +echo Setting default route to a local hub: "$info" |
| 118 | +echo "$info" | xargs ccndc add / udp |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 119 | +echo "$info" | xargs ccndc add /autoconf-route udp |
Alexander Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 120 | + |
Alexander Afanasyev | 9282836 | 2012-10-08 11:24:32 -0700 | [diff] [blame] | 121 | +if [ $MCAST_EXISTED -eq 1 ]; then |
Alexander Afanasyev | e985adc | 2012-10-05 09:18:23 -0700 | [diff] [blame] | 122 | + # destroying multicast face |
| 123 | + ccndstatus | grep 224.0.23.170:59695 | awk '{print $2}' | xargs ccndc destroy face |
| 124 | +fi |
Alexander Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 125 | + |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 126 | diff --git csrc/util/ccnd-publish-local-info.sh csrc/util/ccnd-publish-local-info.sh |
| 127 | new file mode 100755 |
Alexander Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 128 | index 0000000..b433f69 |
Alexander Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 129 | --- /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 Afanasyev | 72af1bf | 2012-10-04 12:14:10 -0700 | [diff] [blame] | 163 | +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 Afanasyev | a556d7e | 2012-10-03 17:35:08 -0700 | [diff] [blame] | 165 | + |
| 166 | diff --git csrc/util/dir.mk csrc/util/dir.mk |
| 167 | index 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) |