1/* 2 ************************************************************************** 3 * Copyright (c) 2015, The Linux Foundation. All rights reserved. 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all copies. 7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 ************************************************************************** 15 */ 16 17/* 18 * nss_nl.h 19 * NSS Netlink internal definitions 20 */ 21#ifndef __NSS_NL_H 22#define __NSS_NL_H 23 24#define NSS_NL_DEBUG_LVL_ERROR 1 25#define NSS_NL_DEBUG_LVL_WARN 2 26#define NSS_NL_DEBUG_LVL_INFO 3 27#define NSS_NL_DEBUG_LVL_TRACE 4 28 29 30#if defined(CONFIG_DYNAMIC_DEBUG) 31/* 32 * Compile messages for dynamic enable/disable 33 */ 34#define nss_nl_error(s, ...) pr_debug("%s[%d]:" s, __func__, __LINE__, ##__VA_ARGS__) 35#define nss_nl_warn(s, ...) pr_debug("%s[%d]:" s, __func__, __LINE__, ##__VA_ARGS__) 36#define nss_nl_info(s, ...) pr_debug("%s[%d]:" s, __func__, __LINE__, ##__VA_ARGS__) 37#define nss_nl_trace(s, ...) pr_debug("%s[%d]:" s, __func__, __LINE__, ##__VA_ARGS__) 38 39#else 40/* 41 * Statically compile messages at different levels 42 */ 43#define nss_nl_error(s, ...) { \ 44 if (NSS_NL_DEBUG_LEVEL < NSS_NL_DEBUG_LVL_ERROR) { \ 45 pr_alert("%s[%d]:" s, __func__, __LINE__, ##__VA_ARGS__); \ 46 } \ 47} 48#define nss_nl_warn(s, ...) { \ 49 if (NSS_NL_DEBUG_LEVEL < NSS_NL_DEBUG_LVL_WARN) { \ 50 pr_warn("%s[%d]:" s, __func__, __LINE__, ##__VA_ARGS__); \ 51 } \ 52} 53#define nss_nl_info(s, ...) { \ 54 if (NSS_NL_DEBUG_LEVEL < NSS_NL_DEBUG_LVL_INFO) { \ 55 pr_notice("%s[%d]:" s, __func__, __LINE__, ##__VA_ARGS__); \ 56 } \ 57} 58#define nss_nl_trace(s, ...) { \ 59 if (NSS_NL_DEBUG_LEVEL < NSS_NL_DEBUG_LVL_TRACE) { \ 60 pr_info("%s[%d]:" s, __func__, __LINE__, ##__VA_ARGS__); \ 61 } \ 62} 63#endif /* !CONFIG_DYNAMIC_DEBUG */ 64 65/* 66 * debug message for module init and exit 67 */ 68#define nss_nl_info_always(s, ...) printk(KERN_INFO"%s[%d]:" s, __func__, __LINE__, ##__VA_ARGS__) 69 70 71#define NSS_NETLINK_INIT_FAMILY(family, pre_fn, post_fn) { \ 72 .id = GENL_ID_GENERATE, \ 73 .name = NSS_NETLINK_##family##FAMILY, \ 74 .hdrsize = 0, \ 75 .version = NSS_NETLINK_VER, \ 76 .maxattr = NSS_NETLINK_##family##_CMD_MAX, \ 77 .netnsok = true, \ 78 .pre_doit = pre_fn, \ 79 .post_doit = post_fn, \ 80} 81 82#define NSS_NETLINK_INIT_POLICY(cmd, ds) { \ 83 .type = NLA_BINARY, \ 84 .len = sizeof(struct ##ds), \ 85} 86 87 88typedef bool (*nss_nl_fn_t)(void); 89 90/* 91 * ************* 92 * Generic API(s) 93 * ************* 94 */ 95 96/* 97 * Allocate NSS NL message buffer, this returns the message SKB and start of the payload pointer 98 */ 99struct sk_buff *nss_nl_new_msg(struct genl_family *family, uint8_t cmd); 100 101/* 102 * Copy NSS NL message buffer into a new SKB 103 */ 104struct sk_buff *nss_nl_copy_msg(struct sk_buff *orig); 105 106/* 107 * Get NSS NL message pointer for a given command 108 */ 109struct nss_nlcmn *nss_nl_get_msg(struct genl_family *family, struct genl_info *info, uint16_t cmd); 110 111/* 112 * returns the start of NSS_NL payload 113 */ 114void *nss_nl_get_data(struct sk_buff *skb); 115 116/* 117 * unicast response to the user 118 */ 119int nss_nl_ucast_resp(struct sk_buff *skb); 120 121/* 122 * multicast response to the user 123 */ 124int nss_nl_mcast_event(struct genl_multicast_group *grp, struct sk_buff *skb); 125 126#endif /* __NSS_NL_H */ 127