Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file common_vty.c |
| 2 | * OpenBSC VTY common helpers. */ |
| 3 | /* |
| 4 | * (C) 2009-2012 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 5 | * (C) 2009-2010 by Holger Hans Peter Freyther |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 16 | * GNU General Public License for more details. |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 17 | * |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | |
| 26 | #include <osmocom/core/talloc.h> |
Harald Welte | 8eda90d | 2012-06-17 12:58:46 +0800 | [diff] [blame] | 27 | #include <osmocom/core/logging.h> |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 28 | |
| 29 | #include <osmocom/vty/telnet_interface.h> |
| 30 | #include <osmocom/vty/command.h> |
| 31 | #include <osmocom/vty/buffer.h> |
| 32 | #include <osmocom/vty/vty.h> |
| 33 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 34 | #include <osmocom/gprs/gprs_msgb.h> |
| 35 | |
| 36 | #include "common_vty.h" |
| 37 | |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 38 | /* Down vty node level. */ |
| 39 | gDEFUN(libgb_exit, |
| 40 | libgb_exit_cmd, "exit", "Exit current mode and down to previous mode\n") |
| 41 | { |
| 42 | switch (vty->node) { |
| 43 | case L_NS_NODE: |
| 44 | case L_BSSGP_NODE: |
| 45 | vty->node = CONFIG_NODE; |
| 46 | vty->index = NULL; |
| 47 | break; |
| 48 | default: |
| 49 | break; |
| 50 | } |
| 51 | return CMD_SUCCESS; |
| 52 | } |
| 53 | |
| 54 | /* End of configuration. */ |
| 55 | gDEFUN(libgb_end, |
| 56 | libgb_end_cmd, "end", "End current mode and change to enable mode.") |
| 57 | { |
| 58 | switch (vty->node) { |
| 59 | case L_NS_NODE: |
| 60 | case L_BSSGP_NODE: |
| 61 | vty_config_unlock(vty); |
| 62 | vty->node = ENABLE_NODE; |
| 63 | vty->index = NULL; |
| 64 | vty->index_sub = NULL; |
| 65 | break; |
| 66 | default: |
| 67 | break; |
| 68 | } |
| 69 | return CMD_SUCCESS; |
| 70 | } |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 71 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 72 | int gprs_log_filter_fn(const struct log_context *ctx, |
| 73 | struct log_target *tar) |
| 74 | { |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 75 | const struct gprs_nsvc *nsvc = ctx->ctx[LOG_CTX_GB_NSVC]; |
| 76 | const struct gprs_bvc *bvc = ctx->ctx[LOG_CTX_GB_BVC]; |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 77 | |
| 78 | /* Filter on the NS Virtual Connection */ |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 79 | if ((tar->filter_map & (1 << LOG_FLT_GB_NSVC)) != 0 |
| 80 | && nsvc && (nsvc == tar->filter_data[LOG_FLT_GB_NSVC])) |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 81 | return 1; |
| 82 | |
| 83 | /* Filter on the NS Virtual Connection */ |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 84 | if ((tar->filter_map & (1 << LOG_FLT_GB_BVC)) != 0 |
| 85 | && bvc && (bvc == tar->filter_data[LOG_FLT_GB_BVC])) |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 86 | return 1; |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 92 | int DNS, DBSSGP; |