^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2014, Ericsson AB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * modification, are permitted provided that the following conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * 2. Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * 3. Neither the names of the copyright holders nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * contributors may be used to endorse or promote products derived from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Alternatively, this software may be distributed under the terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * GNU General Public License ("GPL") version 2 as published by the Free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "bearer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "link.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "name_table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include "socket.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "node.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "net.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <net/genetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/tipc_config.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* The legacy API had an artificial message length limit called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * ULTRA_STRING_MAX_LEN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define ULTRA_STRING_MAX_LEN 32768
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define TIPC_SKB_MAX TLV_SPACE(ULTRA_STRING_MAX_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define REPLY_TRUNCATED "<truncated>\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct tipc_nl_compat_msg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u16 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int rep_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int rep_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int req_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int req_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct sk_buff *rep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct tlv_desc *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct sock *dst_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct tipc_nl_compat_cmd_dump {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int (*header)(struct tipc_nl_compat_msg *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int (*dumpit)(struct sk_buff *, struct netlink_callback *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int (*format)(struct tipc_nl_compat_msg *msg, struct nlattr **attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct tipc_nl_compat_cmd_doit {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int (*doit)(struct sk_buff *skb, struct genl_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int (*transcode)(struct tipc_nl_compat_cmd_doit *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct sk_buff *skb, struct tipc_nl_compat_msg *msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static int tipc_skb_tailroom(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int tailroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) tailroom = skb_tailroom(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) limit = TIPC_SKB_MAX - skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (tailroom < limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return tailroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static inline int TLV_GET_DATA_LEN(struct tlv_desc *tlv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return TLV_GET_LEN(tlv) - TLV_SPACE(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static int tipc_add_tlv(struct sk_buff *skb, u16 type, void *data, u16 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (tipc_skb_tailroom(skb) < TLV_SPACE(len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) skb_put(skb, TLV_SPACE(len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) tlv->tlv_type = htons(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) tlv->tlv_len = htons(TLV_LENGTH(len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (len && data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) memcpy(TLV_DATA(tlv), data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void tipc_tlv_init(struct sk_buff *skb, u16 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct tlv_desc *tlv = (struct tlv_desc *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) TLV_SET_LEN(tlv, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) TLV_SET_TYPE(tlv, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) skb_put(skb, sizeof(struct tlv_desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int tipc_tlv_sprintf(struct sk_buff *skb, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) u16 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u32 rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct tlv_desc *tlv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) rem = tipc_skb_tailroom(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) tlv = (struct tlv_desc *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) len = TLV_GET_LEN(tlv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) buf = TLV_DATA(tlv) + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) n = vscnprintf(buf, rem, fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) TLV_SET_LEN(tlv, n + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) skb_put(skb, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static struct sk_buff *tipc_tlv_alloc(int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) int hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct sk_buff *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) size = TLV_SPACE(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) hdr_len = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) buf = alloc_skb(hdr_len + size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) skb_reserve(buf, hdr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static struct sk_buff *tipc_get_err_tlv(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int str_len = strlen(str) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct sk_buff *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) buf = tipc_tlv_alloc(TLV_SPACE(str_len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) tipc_add_tlv(buf, TIPC_TLV_ERROR_STRING, str, str_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static inline bool string_is_valid(char *s, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return memchr(s, '\0', len) ? true : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct sk_buff *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct genl_dumpit_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct sk_buff *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct nlmsghdr *nlmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct netlink_callback cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct nlattr **attrbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) memset(&cb, 0, sizeof(cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) cb.nlh = (struct nlmsghdr *)arg->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) cb.skb = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) cb.data = &info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) buf = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) buf->sk = msg->dst_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (__tipc_dump_start(&cb, msg->net)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) kfree_skb(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) attrbuf = kcalloc(tipc_genl_family.maxattr + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) sizeof(struct nlattr *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!attrbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) info.attrs = attrbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) err = nlmsg_parse_deprecated(cb.nlh, GENL_HDRLEN, attrbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) tipc_genl_family.maxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) tipc_genl_family.policy, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) len = (*cmd->dumpit)(buf, &cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) nlmsg_for_each_msg(nlmsg, nlmsg_hdr(buf), len, rem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) err = nlmsg_parse_deprecated(nlmsg, GENL_HDRLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) attrbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) tipc_genl_family.maxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) tipc_genl_family.policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) err = (*cmd->format)(msg, attrbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (tipc_skb_tailroom(msg->rep) <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) skb_reset_tail_pointer(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) buf->len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) } while (len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) kfree(attrbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) tipc_dump_done(&cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) kfree_skb(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (err == -EMSGSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* The legacy API only considered messages filling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * "ULTRA_STRING_MAX_LEN" to be truncated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if ((TIPC_SKB_MAX - msg->rep->len) <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) char *tail = skb_tail_pointer(msg->rep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (*tail != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) sprintf(tail - sizeof(REPLY_TRUNCATED) - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) REPLY_TRUNCATED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static int tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct sk_buff *arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (msg->req_type && (!msg->req_size ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) !TLV_CHECK_TYPE(msg->req, msg->req_type)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) msg->rep = tipc_tlv_alloc(msg->rep_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (!msg->rep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (msg->rep_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) tipc_tlv_init(msg->rep, msg->rep_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (cmd->header) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) err = (*cmd->header)(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) kfree_skb(msg->rep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) msg->rep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) arg = nlmsg_new(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (!arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) kfree_skb(msg->rep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) msg->rep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) nlh = nlmsg_put(arg, 0, 0, tipc_genl_family.id, 0, NLM_F_MULTI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (!nlh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) kfree_skb(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) kfree_skb(msg->rep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) msg->rep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) nlmsg_end(arg, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) err = __tipc_nl_compat_dumpit(cmd, msg, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) kfree_skb(msg->rep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) msg->rep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) kfree_skb(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static int __tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct sk_buff *doit_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct sk_buff *trans_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct nlattr **attrbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct genl_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) trans_buf = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (!trans_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) attrbuf = kmalloc_array(tipc_genl_family.maxattr + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) sizeof(struct nlattr *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (!attrbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) goto trans_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) doit_buf = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (!doit_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) goto attrbuf_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) memset(&info, 0, sizeof(info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) info.attrs = attrbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) err = (*cmd->transcode)(cmd, trans_buf, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) goto doit_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) err = nla_parse_deprecated(attrbuf, tipc_genl_family.maxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) (const struct nlattr *)trans_buf->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) trans_buf->len, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) goto doit_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) doit_buf->sk = msg->dst_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) err = (*cmd->doit)(doit_buf, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) doit_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) kfree_skb(doit_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) attrbuf_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) kfree(attrbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) trans_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) kfree_skb(trans_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (msg->req_type && (!msg->req_size ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) !TLV_CHECK_TYPE(msg->req, msg->req_type)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) err = __tipc_nl_compat_doit(cmd, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /* The legacy API considered an empty message a success message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) msg->rep = tipc_tlv_alloc(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (!msg->rep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static int tipc_nl_compat_bearer_dump(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct nlattr *bearer[TIPC_NLA_BEARER_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (!attrs[TIPC_NLA_BEARER])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) err = nla_parse_nested_deprecated(bearer, TIPC_NLA_BEARER_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) attrs[TIPC_NLA_BEARER], NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return tipc_add_tlv(msg->rep, TIPC_TLV_BEARER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) nla_data(bearer[TIPC_NLA_BEARER_NAME]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) nla_len(bearer[TIPC_NLA_BEARER_NAME]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static int tipc_nl_compat_bearer_enable(struct tipc_nl_compat_cmd_doit *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct nlattr *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct nlattr *bearer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) struct tipc_bearer_config *b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) b = (struct tipc_bearer_config *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) bearer = nla_nest_start_noflag(skb, TIPC_NLA_BEARER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (!bearer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) len = TLV_GET_DATA_LEN(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) len -= offsetof(struct tipc_bearer_config, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) len = min_t(int, len, TIPC_MAX_BEARER_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (!string_is_valid(b->name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, b->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (nla_put_u32(skb, TIPC_NLA_BEARER_DOMAIN, ntohl(b->disc_domain)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (ntohl(b->priority) <= TIPC_MAX_LINK_PRI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) prop = nla_nest_start_noflag(skb, TIPC_NLA_BEARER_PROP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (nla_put_u32(skb, TIPC_NLA_PROP_PRIO, ntohl(b->priority)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) nla_nest_end(skb, prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) nla_nest_end(skb, bearer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static int tipc_nl_compat_bearer_disable(struct tipc_nl_compat_cmd_doit *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct nlattr *bearer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) name = (char *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) bearer = nla_nest_start_noflag(skb, TIPC_NLA_BEARER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (!bearer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) len = TLV_GET_DATA_LEN(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) len = min_t(int, len, TIPC_MAX_BEARER_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (!string_is_valid(name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) nla_nest_end(skb, bearer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static inline u32 perc(u32 count, u32 total)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return (count * 100 + (total / 2)) / total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static void __fill_bc_link_stat(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct nlattr *prop[], struct nlattr *stats[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) tipc_tlv_sprintf(msg->rep, " Window:%u packets\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) nla_get_u32(prop[TIPC_NLA_PROP_WIN]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) nla_get_u32(stats[TIPC_NLA_STATS_RX_INFO]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) nla_get_u32(stats[TIPC_NLA_STATS_TX_INFO]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) tipc_tlv_sprintf(msg->rep, " RX naks:%u defs:%u dups:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) nla_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) nla_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) nla_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) tipc_tlv_sprintf(msg->rep, " TX naks:%u acks:%u dups:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) nla_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) nla_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) nla_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) " Congestion link:%u Send queue max:%u avg:%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) nla_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) nla_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) nla_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static int tipc_nl_compat_link_stat_dump(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) struct nlattr *link[TIPC_NLA_LINK_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct nlattr *prop[TIPC_NLA_PROP_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) struct nlattr *stats[TIPC_NLA_STATS_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (!attrs[TIPC_NLA_LINK])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) err = nla_parse_nested_deprecated(link, TIPC_NLA_LINK_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) attrs[TIPC_NLA_LINK], NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!link[TIPC_NLA_LINK_PROP])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) err = nla_parse_nested_deprecated(prop, TIPC_NLA_PROP_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) link[TIPC_NLA_LINK_PROP], NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (!link[TIPC_NLA_LINK_STATS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) err = nla_parse_nested_deprecated(stats, TIPC_NLA_STATS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) link[TIPC_NLA_LINK_STATS], NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) name = (char *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) len = TLV_GET_DATA_LEN(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) len = min_t(int, len, TIPC_MAX_LINK_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (!string_is_valid(name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (strcmp(name, nla_data(link[TIPC_NLA_LINK_NAME])) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) tipc_tlv_sprintf(msg->rep, "\nLink <%s>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) nla_data(link[TIPC_NLA_LINK_NAME]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (link[TIPC_NLA_LINK_BROADCAST]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) __fill_bc_link_stat(msg, prop, stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) if (link[TIPC_NLA_LINK_ACTIVE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) tipc_tlv_sprintf(msg->rep, " ACTIVE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) else if (link[TIPC_NLA_LINK_UP])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) tipc_tlv_sprintf(msg->rep, " STANDBY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) tipc_tlv_sprintf(msg->rep, " DEFUNCT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) tipc_tlv_sprintf(msg->rep, " MTU:%u Priority:%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) nla_get_u32(link[TIPC_NLA_LINK_MTU]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) nla_get_u32(prop[TIPC_NLA_PROP_PRIO]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) tipc_tlv_sprintf(msg->rep, " Tolerance:%u ms Window:%u packets\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) nla_get_u32(prop[TIPC_NLA_PROP_TOL]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) nla_get_u32(prop[TIPC_NLA_PROP_WIN]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) nla_get_u32(link[TIPC_NLA_LINK_RX]) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) nla_get_u32(stats[TIPC_NLA_STATS_RX_INFO]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) nla_get_u32(link[TIPC_NLA_LINK_TX]) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) nla_get_u32(stats[TIPC_NLA_STATS_TX_INFO]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) " TX profile sample:%u packets average:%u octets\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_CNT]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_TOT]) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P1]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P2]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P3]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) tipc_tlv_sprintf(msg->rep, "-16384:%u%% -32768:%u%% -66000:%u%%\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P4]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P5]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P6]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) " RX states:%u probes:%u naks:%u defs:%u dups:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) nla_get_u32(stats[TIPC_NLA_STATS_RX_STATES]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) nla_get_u32(stats[TIPC_NLA_STATS_RX_PROBES]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) nla_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) nla_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) nla_get_u32(stats[TIPC_NLA_STATS_DUPLICATES]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) " TX states:%u probes:%u naks:%u acks:%u dups:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) nla_get_u32(stats[TIPC_NLA_STATS_TX_STATES]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) nla_get_u32(stats[TIPC_NLA_STATS_TX_PROBES]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) nla_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) nla_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) nla_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) tipc_tlv_sprintf(msg->rep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) " Congestion link:%u Send queue max:%u avg:%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) nla_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) nla_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) nla_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static int tipc_nl_compat_link_dump(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) struct nlattr *link[TIPC_NLA_LINK_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) struct tipc_link_info link_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (!attrs[TIPC_NLA_LINK])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) err = nla_parse_nested_deprecated(link, TIPC_NLA_LINK_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) attrs[TIPC_NLA_LINK], NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) link_info.dest = htonl(nla_get_flag(link[TIPC_NLA_LINK_DEST]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) link_info.up = htonl(nla_get_flag(link[TIPC_NLA_LINK_UP]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) nla_strlcpy(link_info.str, link[TIPC_NLA_LINK_NAME],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) TIPC_MAX_LINK_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) return tipc_add_tlv(msg->rep, TIPC_TLV_LINK_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) &link_info, sizeof(link_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) static int __tipc_add_link_prop(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) struct tipc_link_config *lc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) switch (msg->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) case TIPC_CMD_SET_LINK_PRI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return nla_put_u32(skb, TIPC_NLA_PROP_PRIO, ntohl(lc->value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) case TIPC_CMD_SET_LINK_TOL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) return nla_put_u32(skb, TIPC_NLA_PROP_TOL, ntohl(lc->value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) case TIPC_CMD_SET_LINK_WINDOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return nla_put_u32(skb, TIPC_NLA_PROP_WIN, ntohl(lc->value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) static int tipc_nl_compat_media_set(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct nlattr *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) struct nlattr *media;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) struct tipc_link_config *lc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) lc = (struct tipc_link_config *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) media = nla_nest_start_noflag(skb, TIPC_NLA_MEDIA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (!media)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (nla_put_string(skb, TIPC_NLA_MEDIA_NAME, lc->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) prop = nla_nest_start_noflag(skb, TIPC_NLA_MEDIA_PROP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) __tipc_add_link_prop(skb, msg, lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) nla_nest_end(skb, prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) nla_nest_end(skb, media);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) static int tipc_nl_compat_bearer_set(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) struct nlattr *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) struct nlattr *bearer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) struct tipc_link_config *lc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) lc = (struct tipc_link_config *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) bearer = nla_nest_start_noflag(skb, TIPC_NLA_BEARER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if (!bearer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, lc->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) prop = nla_nest_start_noflag(skb, TIPC_NLA_BEARER_PROP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) __tipc_add_link_prop(skb, msg, lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) nla_nest_end(skb, prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) nla_nest_end(skb, bearer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) static int __tipc_nl_compat_link_set(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) struct nlattr *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) struct nlattr *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) struct tipc_link_config *lc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) lc = (struct tipc_link_config *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) link = nla_nest_start_noflag(skb, TIPC_NLA_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) if (!link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (nla_put_string(skb, TIPC_NLA_LINK_NAME, lc->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) prop = nla_nest_start_noflag(skb, TIPC_NLA_LINK_PROP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) __tipc_add_link_prop(skb, msg, lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) nla_nest_end(skb, prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) nla_nest_end(skb, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) static int tipc_nl_compat_link_set(struct tipc_nl_compat_cmd_doit *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) struct tipc_link_config *lc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) struct tipc_bearer *bearer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct tipc_media *media;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) lc = (struct tipc_link_config *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) len = TLV_GET_DATA_LEN(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) len -= offsetof(struct tipc_link_config, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) len = min_t(int, len, TIPC_MAX_LINK_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) if (!string_is_valid(lc->name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) media = tipc_media_find(lc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (media) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) cmd->doit = &__tipc_nl_media_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) return tipc_nl_compat_media_set(skb, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) bearer = tipc_bearer_find(msg->net, lc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) if (bearer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) cmd->doit = &__tipc_nl_bearer_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) return tipc_nl_compat_bearer_set(skb, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return __tipc_nl_compat_link_set(skb, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) static int tipc_nl_compat_link_reset_stats(struct tipc_nl_compat_cmd_doit *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) struct nlattr *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) name = (char *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) link = nla_nest_start_noflag(skb, TIPC_NLA_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (!link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) len = TLV_GET_DATA_LEN(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) len = min_t(int, len, TIPC_MAX_LINK_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) if (!string_is_valid(name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (nla_put_string(skb, TIPC_NLA_LINK_NAME, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) nla_nest_end(skb, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) static int tipc_nl_compat_name_table_dump_header(struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) u32 depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) struct tipc_name_table_query *ntq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) static const char * const header[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) "Type ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) "Lower Upper ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) "Port Identity ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) "Publication Scope"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) ntq = (struct tipc_name_table_query *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (TLV_GET_DATA_LEN(msg->req) < sizeof(struct tipc_name_table_query))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) depth = ntohl(ntq->depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (depth > 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) depth = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) for (i = 0; i < depth; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) tipc_tlv_sprintf(msg->rep, header[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) tipc_tlv_sprintf(msg->rep, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) static int tipc_nl_compat_name_table_dump(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) char port_str[27];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) struct tipc_name_table_query *ntq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) struct nlattr *nt[TIPC_NLA_NAME_TABLE_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) u32 node, depth, type, lowbound, upbound;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) static const char * const scope_str[] = {"", " zone", " cluster",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) " node"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) if (!attrs[TIPC_NLA_NAME_TABLE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) err = nla_parse_nested_deprecated(nt, TIPC_NLA_NAME_TABLE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) attrs[TIPC_NLA_NAME_TABLE], NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) if (!nt[TIPC_NLA_NAME_TABLE_PUBL])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) err = nla_parse_nested_deprecated(publ, TIPC_NLA_PUBL_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) nt[TIPC_NLA_NAME_TABLE_PUBL], NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) ntq = (struct tipc_name_table_query *)TLV_DATA(msg->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) depth = ntohl(ntq->depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) type = ntohl(ntq->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) lowbound = ntohl(ntq->lowbound);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) upbound = ntohl(ntq->upbound);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) if (!(depth & TIPC_NTQ_ALLTYPES) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) (type != nla_get_u32(publ[TIPC_NLA_PUBL_TYPE])))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (lowbound && (lowbound > nla_get_u32(publ[TIPC_NLA_PUBL_UPPER])))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (upbound && (upbound < nla_get_u32(publ[TIPC_NLA_PUBL_LOWER])))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) tipc_tlv_sprintf(msg->rep, "%-10u ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) nla_get_u32(publ[TIPC_NLA_PUBL_TYPE]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (depth == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) tipc_tlv_sprintf(msg->rep, "%-10u %-10u ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) nla_get_u32(publ[TIPC_NLA_PUBL_UPPER]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (depth == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) node = nla_get_u32(publ[TIPC_NLA_PUBL_NODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) sprintf(port_str, "<%u.%u.%u:%u>", tipc_zone(node), tipc_cluster(node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) tipc_node(node), nla_get_u32(publ[TIPC_NLA_PUBL_REF]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) tipc_tlv_sprintf(msg->rep, "%-26s ", port_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (depth == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) tipc_tlv_sprintf(msg->rep, "%-10u %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) nla_get_u32(publ[TIPC_NLA_PUBL_KEY]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) scope_str[nla_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) tipc_tlv_sprintf(msg->rep, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) static int __tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) u32 type, lower, upper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) if (!attrs[TIPC_NLA_PUBL])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) err = nla_parse_nested_deprecated(publ, TIPC_NLA_PUBL_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) attrs[TIPC_NLA_PUBL], NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) type = nla_get_u32(publ[TIPC_NLA_PUBL_TYPE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) lower = nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) upper = nla_get_u32(publ[TIPC_NLA_PUBL_UPPER]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (lower == upper)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) tipc_tlv_sprintf(msg->rep, " {%u,%u}", type, lower);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) tipc_tlv_sprintf(msg->rep, " {%u,%u,%u}", type, lower, upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) static int tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg, u32 sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) void *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) struct nlattr *nest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) struct sk_buff *args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) struct tipc_nl_compat_cmd_dump dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) args = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (!args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) hdr = genlmsg_put(args, 0, 0, &tipc_genl_family, NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) TIPC_NL_PUBL_GET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) if (!hdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) kfree_skb(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) nest = nla_nest_start_noflag(args, TIPC_NLA_SOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) if (!nest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) kfree_skb(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (nla_put_u32(args, TIPC_NLA_SOCK_REF, sock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) kfree_skb(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) nla_nest_end(args, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) genlmsg_end(args, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) dump.dumpit = tipc_nl_publ_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) dump.format = __tipc_nl_compat_publ_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) err = __tipc_nl_compat_dumpit(&dump, msg, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) kfree_skb(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) static int tipc_nl_compat_sk_dump(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) u32 sock_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) struct nlattr *sock[TIPC_NLA_SOCK_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) if (!attrs[TIPC_NLA_SOCK])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) err = nla_parse_nested_deprecated(sock, TIPC_NLA_SOCK_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) attrs[TIPC_NLA_SOCK], NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) sock_ref = nla_get_u32(sock[TIPC_NLA_SOCK_REF]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) tipc_tlv_sprintf(msg->rep, "%u:", sock_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) if (sock[TIPC_NLA_SOCK_CON]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) u32 node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) struct nlattr *con[TIPC_NLA_CON_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) err = nla_parse_nested_deprecated(con, TIPC_NLA_CON_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) sock[TIPC_NLA_SOCK_CON],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) node = nla_get_u32(con[TIPC_NLA_CON_NODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) tipc_tlv_sprintf(msg->rep, " connected to <%u.%u.%u:%u>",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) tipc_zone(node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) tipc_cluster(node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) tipc_node(node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) nla_get_u32(con[TIPC_NLA_CON_SOCK]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (con[TIPC_NLA_CON_FLAG])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) tipc_tlv_sprintf(msg->rep, " via {%u,%u}\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) nla_get_u32(con[TIPC_NLA_CON_TYPE]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) nla_get_u32(con[TIPC_NLA_CON_INST]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) tipc_tlv_sprintf(msg->rep, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) } else if (sock[TIPC_NLA_SOCK_HAS_PUBL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) tipc_tlv_sprintf(msg->rep, " bound to");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) err = tipc_nl_compat_publ_dump(msg, sock_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) tipc_tlv_sprintf(msg->rep, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) static int tipc_nl_compat_media_dump(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) struct nlattr *media[TIPC_NLA_MEDIA_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) if (!attrs[TIPC_NLA_MEDIA])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) err = nla_parse_nested_deprecated(media, TIPC_NLA_MEDIA_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) attrs[TIPC_NLA_MEDIA], NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) return tipc_add_tlv(msg->rep, TIPC_TLV_MEDIA_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) nla_data(media[TIPC_NLA_MEDIA_NAME]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) nla_len(media[TIPC_NLA_MEDIA_NAME]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) static int tipc_nl_compat_node_dump(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) struct tipc_node_info node_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) struct nlattr *node[TIPC_NLA_NODE_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) if (!attrs[TIPC_NLA_NODE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) err = nla_parse_nested_deprecated(node, TIPC_NLA_NODE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) attrs[TIPC_NLA_NODE], NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) node_info.addr = htonl(nla_get_u32(node[TIPC_NLA_NODE_ADDR]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) node_info.up = htonl(nla_get_flag(node[TIPC_NLA_NODE_UP]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) return tipc_add_tlv(msg->rep, TIPC_TLV_NODE_INFO, &node_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) sizeof(node_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) static int tipc_nl_compat_net_set(struct tipc_nl_compat_cmd_doit *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) struct nlattr *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) val = ntohl(*(__be32 *)TLV_DATA(msg->req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) net = nla_nest_start_noflag(skb, TIPC_NLA_NET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) if (!net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if (msg->cmd == TIPC_CMD_SET_NODE_ADDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) if (nla_put_u32(skb, TIPC_NLA_NET_ADDR, val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) } else if (msg->cmd == TIPC_CMD_SET_NETID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (nla_put_u32(skb, TIPC_NLA_NET_ID, val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) nla_nest_end(skb, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) static int tipc_nl_compat_net_dump(struct tipc_nl_compat_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) struct nlattr **attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) __be32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) struct nlattr *net[TIPC_NLA_NET_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) if (!attrs[TIPC_NLA_NET])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) err = nla_parse_nested_deprecated(net, TIPC_NLA_NET_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) attrs[TIPC_NLA_NET], NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) id = htonl(nla_get_u32(net[TIPC_NLA_NET_ID]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) return tipc_add_tlv(msg->rep, TIPC_TLV_UNSIGNED, &id, sizeof(id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) static int tipc_cmd_show_stats_compat(struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) msg->rep = tipc_tlv_alloc(ULTRA_STRING_MAX_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (!msg->rep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) tipc_tlv_init(msg->rep, TIPC_TLV_ULTRA_STRING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) tipc_tlv_sprintf(msg->rep, "TIPC version " TIPC_MOD_VER "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) struct tipc_nl_compat_cmd_dump dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) struct tipc_nl_compat_cmd_doit doit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) memset(&dump, 0, sizeof(dump));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) memset(&doit, 0, sizeof(doit));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) switch (msg->cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) case TIPC_CMD_NOOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) msg->rep = tipc_tlv_alloc(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (!msg->rep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) case TIPC_CMD_GET_BEARER_NAMES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) msg->rep_size = MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) dump.dumpit = tipc_nl_bearer_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) dump.format = tipc_nl_compat_bearer_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) return tipc_nl_compat_dumpit(&dump, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) case TIPC_CMD_ENABLE_BEARER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) msg->req_type = TIPC_TLV_BEARER_CONFIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) doit.doit = __tipc_nl_bearer_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) doit.transcode = tipc_nl_compat_bearer_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) return tipc_nl_compat_doit(&doit, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) case TIPC_CMD_DISABLE_BEARER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) msg->req_type = TIPC_TLV_BEARER_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) doit.doit = __tipc_nl_bearer_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) doit.transcode = tipc_nl_compat_bearer_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) return tipc_nl_compat_doit(&doit, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) case TIPC_CMD_SHOW_LINK_STATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) msg->req_type = TIPC_TLV_LINK_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) msg->rep_size = ULTRA_STRING_MAX_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) msg->rep_type = TIPC_TLV_ULTRA_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) dump.dumpit = tipc_nl_node_dump_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) dump.format = tipc_nl_compat_link_stat_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) return tipc_nl_compat_dumpit(&dump, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) case TIPC_CMD_GET_LINKS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) msg->req_type = TIPC_TLV_NET_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) msg->rep_size = ULTRA_STRING_MAX_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) dump.dumpit = tipc_nl_node_dump_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) dump.format = tipc_nl_compat_link_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) return tipc_nl_compat_dumpit(&dump, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) case TIPC_CMD_SET_LINK_TOL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) case TIPC_CMD_SET_LINK_PRI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) case TIPC_CMD_SET_LINK_WINDOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) msg->req_type = TIPC_TLV_LINK_CONFIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) doit.doit = tipc_nl_node_set_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) doit.transcode = tipc_nl_compat_link_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) return tipc_nl_compat_doit(&doit, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) case TIPC_CMD_RESET_LINK_STATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) msg->req_type = TIPC_TLV_LINK_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) doit.doit = tipc_nl_node_reset_link_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) doit.transcode = tipc_nl_compat_link_reset_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) return tipc_nl_compat_doit(&doit, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) case TIPC_CMD_SHOW_NAME_TABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) msg->req_type = TIPC_TLV_NAME_TBL_QUERY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) msg->rep_size = ULTRA_STRING_MAX_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) msg->rep_type = TIPC_TLV_ULTRA_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) dump.header = tipc_nl_compat_name_table_dump_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) dump.dumpit = tipc_nl_name_table_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) dump.format = tipc_nl_compat_name_table_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) return tipc_nl_compat_dumpit(&dump, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) case TIPC_CMD_SHOW_PORTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) msg->rep_size = ULTRA_STRING_MAX_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) msg->rep_type = TIPC_TLV_ULTRA_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) dump.dumpit = tipc_nl_sk_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) dump.format = tipc_nl_compat_sk_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) return tipc_nl_compat_dumpit(&dump, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) case TIPC_CMD_GET_MEDIA_NAMES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) msg->rep_size = MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) dump.dumpit = tipc_nl_media_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) dump.format = tipc_nl_compat_media_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) return tipc_nl_compat_dumpit(&dump, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) case TIPC_CMD_GET_NODES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) msg->rep_size = ULTRA_STRING_MAX_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) dump.dumpit = tipc_nl_node_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) dump.format = tipc_nl_compat_node_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) return tipc_nl_compat_dumpit(&dump, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) case TIPC_CMD_SET_NODE_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) msg->req_type = TIPC_TLV_NET_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) doit.doit = __tipc_nl_net_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) doit.transcode = tipc_nl_compat_net_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) return tipc_nl_compat_doit(&doit, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) case TIPC_CMD_SET_NETID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) msg->req_type = TIPC_TLV_UNSIGNED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) doit.doit = __tipc_nl_net_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) doit.transcode = tipc_nl_compat_net_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) return tipc_nl_compat_doit(&doit, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) case TIPC_CMD_GET_NETID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) msg->rep_size = sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) dump.dumpit = tipc_nl_net_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) dump.format = tipc_nl_compat_net_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) return tipc_nl_compat_dumpit(&dump, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) case TIPC_CMD_SHOW_STATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) return tipc_cmd_show_stats_compat(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) static int tipc_nl_compat_recv(struct sk_buff *skb, struct genl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) struct tipc_nl_compat_msg msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) struct nlmsghdr *req_nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) struct nlmsghdr *rep_nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) struct tipc_genlmsghdr *req_userhdr = info->userhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) memset(&msg, 0, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) req_nlh = (struct nlmsghdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) msg.req = nlmsg_data(req_nlh) + GENL_HDRLEN + TIPC_GENL_HDRLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) msg.cmd = req_userhdr->cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) msg.net = genl_info_net(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) msg.dst_sk = skb->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) if ((msg.cmd & 0xC000) && (!netlink_net_capable(skb, CAP_NET_ADMIN))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) msg.rep = tipc_get_err_tlv(TIPC_CFG_NOT_NET_ADMIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) err = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) goto send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) msg.req_size = nlmsg_attrlen(req_nlh, GENL_HDRLEN + TIPC_GENL_HDRLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) if (msg.req_size && !TLV_OK(msg.req, msg.req_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) msg.rep = tipc_get_err_tlv(TIPC_CFG_NOT_SUPPORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) goto send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) err = tipc_nl_compat_handle(&msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if ((err == -EOPNOTSUPP) || (err == -EPERM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) msg.rep = tipc_get_err_tlv(TIPC_CFG_NOT_SUPPORTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) else if (err == -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) msg.rep = tipc_get_err_tlv(TIPC_CFG_TLV_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) send:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) if (!msg.rep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) len = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) skb_push(msg.rep, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) rep_nlh = nlmsg_hdr(msg.rep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) memcpy(rep_nlh, info->nlhdr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) rep_nlh->nlmsg_len = msg.rep->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) genlmsg_unicast(msg.net, msg.rep, NETLINK_CB(skb).portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) static const struct genl_small_ops tipc_genl_compat_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) .cmd = TIPC_GENL_CMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) .doit = tipc_nl_compat_recv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) static struct genl_family tipc_genl_compat_family __ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) .name = TIPC_GENL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) .version = TIPC_GENL_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) .hdrsize = TIPC_GENL_HDRLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) .maxattr = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) .netnsok = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) .small_ops = tipc_genl_compat_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) .n_small_ops = ARRAY_SIZE(tipc_genl_compat_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) int __init tipc_netlink_compat_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) res = genl_register_family(&tipc_genl_compat_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) pr_err("Failed to register legacy compat interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) void tipc_netlink_compat_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) genl_unregister_family(&tipc_genl_compat_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) }