/* * Copyright (c) 2015 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "svmdb.h" typedef struct { svmdb_map_args_t map_args; int uid, gid; uword size; } svmdbtool_main_t; svmdbtool_main_t svmdbtool_main; static inline svmdb_map_args_t * map_arg_setup (char *chroot_path) { svmdbtool_main_t *sm = &svmdbtool_main; svmdb_map_args_t *ma = &sm->map_args; memset (ma, 0, sizeof (*ma)); ma->root_path = chroot_path; ma->size = sm->size; ma->uid = sm->uid; ma->gid = sm->gid; return ma; } static void get_string (char *chroot_path, u8 * vbl) { svmdb_client_t *c; char *rv; svmdb_map_args_t *ma; ma = map_arg_setup (chroot_path); c = svmdb_map (ma); rv = svmdb_local_get_string_variable (c, (char *) vbl); fformat (stdout, "%s\n", rv ? rv : "UNSET"); vec_free (rv); svmdb_unmap (c); } static void set_string (char *chroot_path, u8 * vbl, u8 * value) { svmdb_client_t *c; svmdb_map_args_t *ma; ma = map_arg_setup (chroot_path); c = svmdb_map (ma); svmdb_local_set_string_variable (c, (char *) vbl, (char *) value); svmdb_unmap (c); } static void unset_string (char *chroot_path, u8 * vbl) { svmdb_client_t *c; svmdb_map_args_t *ma; ma = map_arg_setup (chroot_path); c = svmdb_map (ma); svmdb_local_unset_string_variable (c, (char *) vbl); svmdb_unmap (c); } static void dump_strings (char *chroot_path) { svmdb_client_t *c; svmdb_map_args_t *ma; ma = map_arg_setup (chroot_path); c = svmdb_map (ma); svmdb_local_dump_strings (c); svmdb_unmap (c); } static void test_vlib_vec_rate (char *chroot_path, f64 vr) { svmdb_client_t *c; f64 *tv = 0; svmdb_map_args_t *ma; ma = map_arg_setup (chroot_path); c = svmdb_map (ma); vec_add1 (tv, vr); svmdb_local_set_vec_variable (c, "vlib_vector_rate", (char *) tv, sizeof (*tv)); svmdb_unmap (c); vec_free (tv); } static void test_vec (char *chroot_path, u8 * vbl) { svmdb_client_t *c; u64 *tv = 0; int i; svmdb_map_args_t *ma; ma = map_arg_setup (chroot_path); c = svmdb_map (ma); /* my amp goes to 11 */ for (i = 0; i < 11; i++) { vec_add1 (tv, i); } svmdb_local_set_vec_variable (c, (char *) vbl, (char *) tv, sizeof (tv[0])); svmdb_unmap (c); vec_free (tv); } static void fake_install (char *chroot_path, u8 * add_value) { svmdb_client_t *c; u8 *v = 0; u8 **values = 0; u8 *oldvalue; u8 *value; int nitems = 0, i; serialize_main_t m; svmdb_map_args_t *ma; ma = map_arg_setup (chroot_path); c = svmdb_map (ma); oldvalue = svmdb_local_get_vec_variable (c, "installed_sw", 1); if (oldvalue) { unserialize_open_data (&m, oldvalue, vec_len (oldvalue)); nitems = unserialize_likely_small_unsigned_integer (&m); for (i = 0; i < nitems; i++) { unserialize_cstring (&m, (char **) &value); vec_add1 (values, value); } vec_free (v); } nitems++; value = format (0, "%s%c", add_value, 0); vec_add1 (values, value); fformat (stdout, "Resulting installed_sw vector:\n"); serialize_open_vector (&m, v); serialize_likely_small_unsigned_integer (&m, vec_len (values)); for (i = 0; i < vec_len (values); i++) { fformat (stdout, "%s\n", values[i]); serialize_cstring (&m, (char *) values[i]); } v = serialize_close_vector (&m); svmdb_local_set_vec_variable (c, "installed_sw", v, sizeof (v[0])); svmdb_unmap (c); for (i = 0; i < vec_len (values); i++) vec_free (values[i]); vec_free (values); } static void sigaction_handler (int signum, siginfo_t * i, void *notused) { u32 action, opaque; action = (u32) (uword) i->si_ptr; action >>= 28; opaque = (u32) (uword) i->si_ptr; opaque &= ~(0xF0000000); clib_warning ("signal %d, action %d, opaque %x", signum, action, opaque); } static void test_reg (char *chroot_path, u8 * vbl) { svmdb_client_t *c; svmdb_notification_args_t args; svmdb_notification_args_t *a = &args; struct sigaction sa; svmdb_map_args_t *ma; ma = map_arg_setup (chroot_path); memset (&sa, 0, sizeof (sa)); sa.sa_sigaction = sigaction_handler; sa.sa_flags = SA_SIGINFO; if (sigaction (SIGUSR2, &sa, 0) < 0)
---
name: Cloud NAT
maintainer: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
features:
  -