1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef NSTACKX_NLMSG_H
17 #define NSTACKX_NLMSG_H
18 #include <linux/rtnetlink.h>
19 #include <linux/gen_stats.h>
20 #include <linux/pkt_sched.h>
21
22 #include <asm/types.h>
23 #include <sys/socket.h>
24 #include <net/if.h>
25 #include <unistd.h>
26
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <securec.h>
32
33 #define MAX_NETLINK_BUFFER_LEN 32768
34
35 typedef void (*NLCB)(struct nlmsghdr *h, void *arg, void *value);
36 struct NlmsgCallback {
37 NLCB nlcb;
38 void *arg;
39 void *value;
40 };
41
NlMax(int32_t a,int32_t b)42 static inline int32_t NlMax(int32_t a, int32_t b)
43 {
44 return (a < b) ? b : a;
45 }
46
NlMin(int32_t a,int32_t b)47 static inline int32_t NlMin(int32_t a, int32_t b)
48 {
49 return (a < b) ? a : b;
50 }
51
52 int32_t NetlinkSocketInit();
53 int32_t SendNetlinkRequest(int32_t nlSockFd, int32_t ifIndex, uint16_t type);
54 int32_t RecvNetlinkResponse(int32_t nlSockFd, struct NlmsgCallback *nlcb);
55 void RecvNetlinkParseAttr(struct rtattr *rta, int32_t len, struct rtattr *tb[], int32_t max);
56 #endif
57