Skip to content

Commit

Permalink
Add NCD, the Network Configuration Daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrop7 committed Dec 10, 2010
1 parent f915658 commit 20d7a01
Show file tree
Hide file tree
Showing 35 changed files with 10,360 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ add_subdirectory(security)
add_subdirectory(socksclient)
add_subdirectory(lwip)
add_subdirectory(dhcpclient)
add_subdirectory(ncdconfig)
if (NOT WIN32)
add_subdirectory(ipc)
endif ()
Expand All @@ -109,3 +110,8 @@ add_subdirectory(flooder)

# tun2socks
add_subdirectory(tun2socks)

# ncd
if (NOT WIN32)
add_subdirectory(ncd)
endif ()
2 changes: 2 additions & 0 deletions blog_channels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ server 4
client 4
flooder 4
tun2socks 4
ncd 4
StreamPeerIO 4
DatagramPeerIO 4
BReactor 3
Expand All @@ -15,3 +16,4 @@ FrameDecider 4
BSocksClient 4
BDHCPClientCore 4
BDHCPClient 4
NCDIfConfig 4
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ target_link_libraries(bavl_test security)
add_executable(bencryption_bench bencryption_bench.c)
target_link_libraries(bencryption_bench system security)

add_executable(ncd_tokenizer_test ncd_tokenizer_test.c)
target_link_libraries(ncd_tokenizer_test ncdconfig)

add_executable(ncd_parser_test ncd_parser_test.c)
target_link_libraries(ncd_parser_test ncdconfig)

if (NOT WIN32)
add_executable(ipc_server ipc_server.c)
target_link_libraries(ipc_server ipc)
Expand Down
84 changes: 84 additions & 0 deletions examples/ncd_parser_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* @file ncd_tokenizer_test.c
* @author Ambroz Bizjak <[email protected]>
*
* @section LICENSE
*
* This file is part of BadVPN.
*
* BadVPN is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* BadVPN is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <stddef.h>
#include <stdio.h>
#include <string.h>

#include <misc/debug.h>
#include <ncdconfig/NCDConfigParser.h>

int error;

int main (int argc, char **argv)
{
if (argc < 1) {
return 1;
}

if (argc != 2) {
printf("Usage: %s <string>\n", argv[0]);
return 1;
}

// parse
struct NCDConfig_interfaces *ast;
if (!NCDConfigParser_Parse(argv[1], strlen(argv[1]), &ast)) {
DEBUG("NCDConfigParser_Parse failed");
return 1;
}

// print
struct NCDConfig_interfaces *iface = ast;
while (iface) {
printf("Interface %s\n", iface->name);

struct NCDConfig_statements *st = iface->statements;
while (st) {
struct NCDConfig_strings *name = st->names;
ASSERT(name)
printf(" %s", name->value);
name = name->next;

while (name) {
printf(".%s", name->value);
name = name->next;
}

printf("\n");

struct NCDConfig_strings *arg = st->args;
while (arg) {
printf(" %s\n", arg->value);
arg = arg->next;
}

st = st->next;
}

iface = iface->next;
}

NCDConfig_free_interfaces(ast);

return 0;
}
92 changes: 92 additions & 0 deletions examples/ncd_tokenizer_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* @file ncd_tokenizer_test.c
* @author Ambroz Bizjak <[email protected]>
*
* @section LICENSE
*
* This file is part of BadVPN.
*
* BadVPN is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* BadVPN is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <stddef.h>
#include <stdio.h>
#include <string.h>

#include <misc/debug.h>
#include <ncdconfig/NCDConfigTokenizer.h>

int error;

static int tokenizer_output (void *user, int token, char *value, size_t pos)
{
if (token == NCD_ERROR) {
printf("error at %zd\n", pos);
error = 1;
return 0;
}

switch (token) {
case NCD_EOF:
printf("eof\n");
break;
case NCD_TOKEN_CURLY_OPEN:
printf("curly_open\n");
break;
case NCD_TOKEN_CURLY_CLOSE:
printf("curly_close\n");
break;
case NCD_TOKEN_SEMICOLON:
printf("semicolon\n");
break;
case NCD_TOKEN_DOT:
printf("dot\n");
break;
case NCD_TOKEN_INTERFACE:
printf("interface\n");
break;
case NCD_TOKEN_NAME:
printf("name %s\n", value);
break;
case NCD_TOKEN_STRING:
printf("string %s\n", value);
break;
default:
ASSERT(0);
}

return 1;
}

int main (int argc, char **argv)
{
if (argc < 1) {
return 1;
}

if (argc != 2) {
printf("Usage: %s <string>\n", argv[0]);
return 1;
}

error = 0;

NCDConfigTokenizer_Tokenize(argv[1], strlen(argv[1]), tokenizer_output, NULL);

if (error) {
return 1;
}

return 0;
}
12 changes: 12 additions & 0 deletions generate_files
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ function do_bison() {
"${BISON_CMD[@]}" -d -o "${OUT_DIR}/bison_${name}.c" "${input}"
}

function do_lemon() {
local input="$1"
local name=$(basename "${input}")
(
cd generated &&
rm -f "${name}" &&
cp ../"${input}" "${name}" &&
../lemon/lemon "${name}"
)
}

mkdir -p generated

bproto tests/bproto_test.bproto bproto_test
Expand All @@ -42,3 +53,4 @@ bstruct security/OTPChecker.bstruct OTPChecker
do_flex predicate/BPredicate.l BPredicate
do_bison predicate/BPredicate.y BPredicate
"${PHP_CMD[@]}" blog_generator/blog.php --input-file blog_channels.txt --output-dir "${OUT_DIR}"
do_lemon ncdconfig/NCDConfigParser_parse.y
Loading

0 comments on commit 20d7a01

Please sign in to comment.