Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * net/tipc/netlink.c: TIPC configuration handling
0003  *
0004  * Copyright (c) 2005-2006, 2014, Ericsson AB
0005  * Copyright (c) 2005-2007, Wind River Systems
0006  * All rights reserved.
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions are met:
0010  *
0011  * 1. Redistributions of source code must retain the above copyright
0012  *    notice, this list of conditions and the following disclaimer.
0013  * 2. Redistributions in binary form must reproduce the above copyright
0014  *    notice, this list of conditions and the following disclaimer in the
0015  *    documentation and/or other materials provided with the distribution.
0016  * 3. Neither the names of the copyright holders nor the names of its
0017  *    contributors may be used to endorse or promote products derived from
0018  *    this software without specific prior written permission.
0019  *
0020  * Alternatively, this software may be distributed under the terms of the
0021  * GNU General Public License ("GPL") version 2 as published by the Free
0022  * Software Foundation.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include "core.h"
0038 #include "socket.h"
0039 #include "name_table.h"
0040 #include "bearer.h"
0041 #include "link.h"
0042 #include "node.h"
0043 #include "net.h"
0044 #include "udp_media.h"
0045 #include <net/genetlink.h>
0046 
0047 static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = {
0048     [TIPC_NLA_UNSPEC]   = { .type = NLA_UNSPEC, },
0049     [TIPC_NLA_BEARER]   = { .type = NLA_NESTED, },
0050     [TIPC_NLA_SOCK]     = { .type = NLA_NESTED, },
0051     [TIPC_NLA_PUBL]     = { .type = NLA_NESTED, },
0052     [TIPC_NLA_LINK]     = { .type = NLA_NESTED, },
0053     [TIPC_NLA_MEDIA]    = { .type = NLA_NESTED, },
0054     [TIPC_NLA_NODE]     = { .type = NLA_NESTED, },
0055     [TIPC_NLA_NET]      = { .type = NLA_NESTED, },
0056     [TIPC_NLA_NAME_TABLE]   = { .type = NLA_NESTED, },
0057     [TIPC_NLA_MON]      = { .type = NLA_NESTED, },
0058 };
0059 
0060 const struct nla_policy
0061 tipc_nl_name_table_policy[TIPC_NLA_NAME_TABLE_MAX + 1] = {
0062     [TIPC_NLA_NAME_TABLE_UNSPEC]    = { .type = NLA_UNSPEC },
0063     [TIPC_NLA_NAME_TABLE_PUBL]  = { .type = NLA_NESTED }
0064 };
0065 
0066 const struct nla_policy tipc_nl_monitor_policy[TIPC_NLA_MON_MAX + 1] = {
0067     [TIPC_NLA_MON_UNSPEC]           = { .type = NLA_UNSPEC },
0068     [TIPC_NLA_MON_REF]          = { .type = NLA_U32 },
0069     [TIPC_NLA_MON_ACTIVATION_THRESHOLD] = { .type = NLA_U32 },
0070 };
0071 
0072 const struct nla_policy tipc_nl_sock_policy[TIPC_NLA_SOCK_MAX + 1] = {
0073     [TIPC_NLA_SOCK_UNSPEC]      = { .type = NLA_UNSPEC },
0074     [TIPC_NLA_SOCK_ADDR]        = { .type = NLA_U32 },
0075     [TIPC_NLA_SOCK_REF]     = { .type = NLA_U32 },
0076     [TIPC_NLA_SOCK_CON]     = { .type = NLA_NESTED },
0077     [TIPC_NLA_SOCK_HAS_PUBL]    = { .type = NLA_FLAG }
0078 };
0079 
0080 const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = {
0081     [TIPC_NLA_NET_UNSPEC]       = { .type = NLA_UNSPEC },
0082     [TIPC_NLA_NET_ID]       = { .type = NLA_U32 },
0083     [TIPC_NLA_NET_ADDR]     = { .type = NLA_U32 },
0084     [TIPC_NLA_NET_NODEID]       = { .type = NLA_U64 },
0085     [TIPC_NLA_NET_NODEID_W1]    = { .type = NLA_U64 },
0086     [TIPC_NLA_NET_ADDR_LEGACY]  = { .type = NLA_FLAG }
0087 };
0088 
0089 const struct nla_policy tipc_nl_link_policy[TIPC_NLA_LINK_MAX + 1] = {
0090     [TIPC_NLA_LINK_UNSPEC]      = { .type = NLA_UNSPEC },
0091     [TIPC_NLA_LINK_NAME]        = { .type = NLA_STRING,
0092                         .len = TIPC_MAX_LINK_NAME },
0093     [TIPC_NLA_LINK_MTU]     = { .type = NLA_U32 },
0094     [TIPC_NLA_LINK_BROADCAST]   = { .type = NLA_FLAG },
0095     [TIPC_NLA_LINK_UP]      = { .type = NLA_FLAG },
0096     [TIPC_NLA_LINK_ACTIVE]      = { .type = NLA_FLAG },
0097     [TIPC_NLA_LINK_PROP]        = { .type = NLA_NESTED },
0098     [TIPC_NLA_LINK_STATS]       = { .type = NLA_NESTED },
0099     [TIPC_NLA_LINK_RX]      = { .type = NLA_U32 },
0100     [TIPC_NLA_LINK_TX]      = { .type = NLA_U32 }
0101 };
0102 
0103 const struct nla_policy tipc_nl_node_policy[TIPC_NLA_NODE_MAX + 1] = {
0104     [TIPC_NLA_NODE_UNSPEC]      = { .type = NLA_UNSPEC },
0105     [TIPC_NLA_NODE_ADDR]        = { .type = NLA_U32 },
0106     [TIPC_NLA_NODE_UP]      = { .type = NLA_FLAG },
0107     [TIPC_NLA_NODE_ID]      = { .type = NLA_BINARY,
0108                         .len = TIPC_NODEID_LEN},
0109     [TIPC_NLA_NODE_KEY]     = { .type = NLA_BINARY,
0110                         .len = TIPC_AEAD_KEY_SIZE_MAX},
0111     [TIPC_NLA_NODE_KEY_MASTER]  = { .type = NLA_FLAG },
0112     [TIPC_NLA_NODE_REKEYING]    = { .type = NLA_U32 },
0113 };
0114 
0115 /* Properties valid for media, bearer and link */
0116 const struct nla_policy tipc_nl_prop_policy[TIPC_NLA_PROP_MAX + 1] = {
0117     [TIPC_NLA_PROP_UNSPEC]      = { .type = NLA_UNSPEC },
0118     [TIPC_NLA_PROP_PRIO]        = { .type = NLA_U32 },
0119     [TIPC_NLA_PROP_TOL]     = { .type = NLA_U32 },
0120     [TIPC_NLA_PROP_WIN]     = { .type = NLA_U32 },
0121     [TIPC_NLA_PROP_MTU]     = { .type = NLA_U32 },
0122     [TIPC_NLA_PROP_BROADCAST]   = { .type = NLA_U32 },
0123     [TIPC_NLA_PROP_BROADCAST_RATIO] = { .type = NLA_U32 }
0124 };
0125 
0126 const struct nla_policy tipc_nl_bearer_policy[TIPC_NLA_BEARER_MAX + 1]  = {
0127     [TIPC_NLA_BEARER_UNSPEC]    = { .type = NLA_UNSPEC },
0128     [TIPC_NLA_BEARER_NAME]      = { .type = NLA_STRING,
0129                         .len = TIPC_MAX_BEARER_NAME },
0130     [TIPC_NLA_BEARER_PROP]      = { .type = NLA_NESTED },
0131     [TIPC_NLA_BEARER_DOMAIN]    = { .type = NLA_U32 }
0132 };
0133 
0134 const struct nla_policy tipc_nl_media_policy[TIPC_NLA_MEDIA_MAX + 1] = {
0135     [TIPC_NLA_MEDIA_UNSPEC]     = { .type = NLA_UNSPEC },
0136     [TIPC_NLA_MEDIA_NAME]       = { .type = NLA_STRING },
0137     [TIPC_NLA_MEDIA_PROP]       = { .type = NLA_NESTED }
0138 };
0139 
0140 const struct nla_policy tipc_nl_udp_policy[TIPC_NLA_UDP_MAX + 1] = {
0141     [TIPC_NLA_UDP_UNSPEC]   = {.type = NLA_UNSPEC},
0142     [TIPC_NLA_UDP_LOCAL]    = {.type = NLA_BINARY,
0143                    .len = sizeof(struct sockaddr_storage)},
0144     [TIPC_NLA_UDP_REMOTE]   = {.type = NLA_BINARY,
0145                    .len = sizeof(struct sockaddr_storage)},
0146 };
0147 
0148 /* Users of the legacy API (tipc-config) can't handle that we add operations,
0149  * so we have a separate genl handling for the new API.
0150  */
0151 static const struct genl_ops tipc_genl_v2_ops[] = {
0152     {
0153         .cmd    = TIPC_NL_BEARER_DISABLE,
0154         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0155         .doit   = tipc_nl_bearer_disable,
0156     },
0157     {
0158         .cmd    = TIPC_NL_BEARER_ENABLE,
0159         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0160         .doit   = tipc_nl_bearer_enable,
0161     },
0162     {
0163         .cmd    = TIPC_NL_BEARER_GET,
0164         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0165         .doit   = tipc_nl_bearer_get,
0166         .dumpit = tipc_nl_bearer_dump,
0167     },
0168     {
0169         .cmd    = TIPC_NL_BEARER_ADD,
0170         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0171         .doit   = tipc_nl_bearer_add,
0172     },
0173     {
0174         .cmd    = TIPC_NL_BEARER_SET,
0175         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0176         .doit   = tipc_nl_bearer_set,
0177     },
0178     {
0179         .cmd    = TIPC_NL_SOCK_GET,
0180         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0181         .start = tipc_dump_start,
0182         .dumpit = tipc_nl_sk_dump,
0183         .done   = tipc_dump_done,
0184     },
0185     {
0186         .cmd    = TIPC_NL_PUBL_GET,
0187         .validate = GENL_DONT_VALIDATE_STRICT |
0188                 GENL_DONT_VALIDATE_DUMP_STRICT,
0189         .dumpit = tipc_nl_publ_dump,
0190     },
0191     {
0192         .cmd    = TIPC_NL_LINK_GET,
0193         .validate = GENL_DONT_VALIDATE_STRICT,
0194         .doit   = tipc_nl_node_get_link,
0195         .dumpit = tipc_nl_node_dump_link,
0196     },
0197     {
0198         .cmd    = TIPC_NL_LINK_SET,
0199         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0200         .doit   = tipc_nl_node_set_link,
0201     },
0202     {
0203         .cmd    = TIPC_NL_LINK_RESET_STATS,
0204         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0205         .doit   = tipc_nl_node_reset_link_stats,
0206     },
0207     {
0208         .cmd    = TIPC_NL_MEDIA_GET,
0209         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0210         .doit   = tipc_nl_media_get,
0211         .dumpit = tipc_nl_media_dump,
0212     },
0213     {
0214         .cmd    = TIPC_NL_MEDIA_SET,
0215         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0216         .doit   = tipc_nl_media_set,
0217     },
0218     {
0219         .cmd    = TIPC_NL_NODE_GET,
0220         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0221         .dumpit = tipc_nl_node_dump,
0222     },
0223     {
0224         .cmd    = TIPC_NL_NET_GET,
0225         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0226         .dumpit = tipc_nl_net_dump,
0227     },
0228     {
0229         .cmd    = TIPC_NL_NET_SET,
0230         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0231         .doit   = tipc_nl_net_set,
0232     },
0233     {
0234         .cmd    = TIPC_NL_NAME_TABLE_GET,
0235         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0236         .dumpit = tipc_nl_name_table_dump,
0237     },
0238     {
0239         .cmd    = TIPC_NL_MON_SET,
0240         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0241         .doit   = tipc_nl_node_set_monitor,
0242     },
0243     {
0244         .cmd    = TIPC_NL_MON_GET,
0245         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0246         .doit   = tipc_nl_node_get_monitor,
0247         .dumpit = tipc_nl_node_dump_monitor,
0248     },
0249     {
0250         .cmd    = TIPC_NL_MON_PEER_GET,
0251         .validate = GENL_DONT_VALIDATE_STRICT |
0252                 GENL_DONT_VALIDATE_DUMP_STRICT,
0253         .dumpit = tipc_nl_node_dump_monitor_peer,
0254     },
0255     {
0256         .cmd    = TIPC_NL_PEER_REMOVE,
0257         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0258         .doit   = tipc_nl_peer_rm,
0259     },
0260 #ifdef CONFIG_TIPC_MEDIA_UDP
0261     {
0262         .cmd    = TIPC_NL_UDP_GET_REMOTEIP,
0263         .validate = GENL_DONT_VALIDATE_STRICT |
0264                 GENL_DONT_VALIDATE_DUMP_STRICT,
0265         .dumpit = tipc_udp_nl_dump_remoteip,
0266     },
0267 #endif
0268 #ifdef CONFIG_TIPC_CRYPTO
0269     {
0270         .cmd    = TIPC_NL_KEY_SET,
0271         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0272         .doit   = tipc_nl_node_set_key,
0273     },
0274     {
0275         .cmd    = TIPC_NL_KEY_FLUSH,
0276         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0277         .doit   = tipc_nl_node_flush_key,
0278     },
0279 #endif
0280     {
0281         .cmd    = TIPC_NL_ADDR_LEGACY_GET,
0282         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0283         .doit   = tipc_nl_net_addr_legacy_get,
0284     },
0285 };
0286 
0287 struct genl_family tipc_genl_family __ro_after_init = {
0288     .name       = TIPC_GENL_V2_NAME,
0289     .version    = TIPC_GENL_V2_VERSION,
0290     .hdrsize    = 0,
0291     .maxattr    = TIPC_NLA_MAX,
0292     .policy     = tipc_nl_policy,
0293     .netnsok    = true,
0294     .module     = THIS_MODULE,
0295     .ops        = tipc_genl_v2_ops,
0296     .n_ops      = ARRAY_SIZE(tipc_genl_v2_ops),
0297 };
0298 
0299 int __init tipc_netlink_start(void)
0300 {
0301     int res;
0302 
0303     res = genl_register_family(&tipc_genl_family);
0304     if (res) {
0305         pr_err("Failed to register netlink interface\n");
0306         return res;
0307     }
0308     return 0;
0309 }
0310 
0311 void tipc_netlink_stop(void)
0312 {
0313     genl_unregister_family(&tipc_genl_family);
0314 }