summaryrefslogtreecommitdiff
path: root/sys/compat/linux/linux_netlink.c
blob: 6dd2ad7ad8b05816db7b38896f9850ae4015f305 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2022 Alexander V. Chernikov
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include "opt_inet.h"
#include "opt_inet6.h"

#include <sys/types.h>
#include <sys/ck.h>
#include <sys/lock.h>
#include <sys/socket.h>
#include <sys/vnode.h>

#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <net/route/nhop.h>
#include <net/route/route_ctl.h>
#include <netlink/netlink.h>
#include <netlink/netlink_ctl.h>
#include <netlink/netlink_linux.h>
#include <netlink/netlink_var.h>
#include <netlink/netlink_route.h>

#include <compat/linux/linux.h>
#include <compat/linux/linux_common.h>
#include <compat/linux/linux_util.h>

#define	DEBUG_MOD_NAME	nl_linux
#define	DEBUG_MAX_LEVEL	LOG_DEBUG3
#include <netlink/netlink_debug.h>
_DECLARE_DEBUG(LOG_INFO);

static bool
valid_rta_size(const struct rtattr *rta, int sz)
{
	return (NL_RTA_DATA_LEN(rta) == sz);
}

static bool
valid_rta_u32(const struct rtattr *rta)
{
	return (valid_rta_size(rta, sizeof(uint32_t)));
}

static uint32_t
_rta_get_uint32(const struct rtattr *rta)
{
	return (*((const uint32_t *)NL_RTA_DATA_CONST(rta)));
}

static int
rtnl_neigh_from_linux(struct nlmsghdr *hdr, struct nl_pstate *npt)
{
	struct ndmsg *ndm = (struct ndmsg *)(hdr + 1);
	sa_family_t f;

	if (hdr->nlmsg_len < sizeof(struct nlmsghdr) + sizeof(struct ndmsg))
		return (EBADMSG);
	if ((f = linux_to_bsd_domain(ndm->ndm_family)) == AF_UNKNOWN)
		return (EPFNOSUPPORT);

	ndm->ndm_family = f;

	return (0);
}

static int
rtnl_ifaddr_from_linux(struct nlmsghdr *hdr, struct nl_pstate *npt)
{
	struct ifaddrmsg *ifam = (struct ifaddrmsg *)(hdr + 1);
	sa_family_t f;

	if (hdr->nlmsg_len < sizeof(struct nlmsghdr) +
	    offsetof(struct ifaddrmsg, ifa_family) + sizeof(ifam->ifa_family))
		return (EBADMSG);
	if ((f = linux_to_bsd_domain(ifam->ifa_family)) == AF_UNKNOWN)
		return (EPFNOSUPPORT);

	ifam->ifa_family = f;

	return (0);
}

/*
 * XXX: in case of error state of hdr is inconsistent.
 */
static int
rtnl_route_from_linux(struct nlmsghdr *hdr, struct nl_pstate *npt)
{
	/* Tweak address families and default fib only */
	struct rtmsg *rtm = (struct rtmsg *)(hdr + 1);
	struct nlattr *nla, *nla_head;
	int attrs_len;
	sa_family_t f;

	if (hdr->nlmsg_len < sizeof(struct nlmsghdr) + sizeof(struct rtmsg))
		return (EBADMSG);
	if ((f = linux_to_bsd_domain(rtm->rtm_family)) == AF_UNKNOWN)
		return (EPFNOSUPPORT);
	rtm->rtm_family = f;

	if (rtm->rtm_table == 254)
		rtm->rtm_table = 0;

	attrs_len = hdr->nlmsg_len - sizeof(struct nlmsghdr);
	attrs_len -= NETLINK_ALIGN(sizeof(struct rtmsg));
	nla_head = (struct nlattr *)((char *)rtm + NETLINK_ALIGN(sizeof(struct rtmsg)));

	NLA_FOREACH(nla, nla_head, attrs_len) {
		RT_LOG(LOG_DEBUG3, "GOT type %d len %d total %d",
		    nla->nla_type, nla->nla_len, attrs_len);
		struct rtattr *rta = (struct rtattr *)nla;
		if (rta->rta_len < sizeof(struct rtattr)) {
			break;
		}
		switch (rta->rta_type) {
		case NL_RTA_TABLE:
			if (!valid_rta_u32(rta))
				return (EBADMSG);
			rtm->rtm_table = 0;
			uint32_t fibnum = _rta_get_uint32(rta);
			RT_LOG(LOG_DEBUG3, "GET RTABLE: %u", fibnum);
			if (fibnum == 254) {
				*((uint32_t *)NL_RTA_DATA(rta)) = 0;
			}
			break;
		}
	}

	return (0);
}

static int
rtnl_from_linux(struct nlmsghdr *hdr, struct nl_pstate *npt)
{

	switch (hdr->nlmsg_type) {
	case NL_RTM_GETROUTE:
	case NL_RTM_NEWROUTE:
	case NL_RTM_DELROUTE:
		return (rtnl_route_from_linux(hdr, npt));
	case NL_RTM_GETNEIGH:
		return (rtnl_neigh_from_linux(hdr, npt));
	case NL_RTM_GETADDR:
		return (rtnl_ifaddr_from_linux(hdr, npt));
	/* Silence warning for the messages where no translation is required */
	case NL_RTM_NEWLINK:
	case NL_RTM_DELLINK:
	case NL_RTM_GETLINK:
		break;
	default:
		RT_LOG(LOG_DEBUG, "Passing message type %d untranslated",
		    hdr->nlmsg_type);
		/* XXXGL: maybe return error? */
	}

	return (0);
}

static int
nlmsg_from_linux(int netlink_family, struct nlmsghdr **hdr,
    struct nl_pstate *npt)
{
	switch (netlink_family) {
	case NETLINK_ROUTE:
		return (rtnl_from_linux(*hdr, npt));
	}

	return (0);
}


/************************************************************
 * Kernel -> Linux
 ************************************************************/

static bool
handle_default_out(struct nlmsghdr *hdr, struct nl_writer *nw)
{
	char *out_hdr;
	out_hdr = nlmsg_reserve_data(nw, NLMSG_ALIGN(hdr->nlmsg_len), char);

	if (out_hdr != NULL) {
		memcpy(out_hdr, hdr, hdr->nlmsg_len);
		nw->num_messages++;
		return (true);
	}
	return (false);
}

static bool
nlmsg_copy_header(struct nlmsghdr *hdr, struct nl_writer *nw)
{
	return (nlmsg_add(nw, hdr->nlmsg_pid, hdr->nlmsg_seq, hdr->nlmsg_type,
	    hdr->nlmsg_flags, 0));
}

static void *
_nlmsg_copy_next_header(struct nlmsghdr *hdr, struct nl_writer *nw, int sz)
{
	void *next_hdr = nlmsg_reserve_data(nw, sz, void);
	memcpy(next_hdr, hdr + 1, NLMSG_ALIGN(sz));

	return (next_hdr);
}
#define	nlmsg_copy_next_header(_hdr, _ns, _t)	\
	((_t *)(_nlmsg_copy_next_header(_hdr, _ns, sizeof(_t))))

static bool
nlmsg_copy_nla(const struct nlattr *nla_orig, struct nl_writer *nw)
{
	struct nlattr *nla = nlmsg_reserve_data(nw, nla_orig->nla_len, struct nlattr);
	if (nla != NULL) {
		memcpy(nla, nla_orig, nla_orig->nla_len);
		return (true);
	}
	return (false);
}

/*
 * Translate a FreeBSD interface name to a Linux interface name.
 */
static bool
nlmsg_translate_ifname_nla(struct nlattr *nla, struct nl_writer *nw)
{
	char ifname[LINUX_IFNAMSIZ];

	if (nw->ifp == NULL)
		return (false);
	(void)ifname_bsd_to_linux_ifp(nw->ifp, ifname, sizeof(ifname));
	return (nlattr_add_string(nw, IFLA_IFNAME, ifname));
}

#define	LINUX_NLA_UNHANDLED	-1
/*
 * Translate a FreeBSD attribute to a Linux attribute.
 * Returns LINUX_NLA_UNHANDLED when the attribute is not processed
 * and the caller must take care of it, otherwise the result is returned.
 */
static int
nlmsg_translate_all_nla(struct nlmsghdr *hdr, struct nlattr *nla,
    struct nl_writer *nw)
{

	switch (hdr->nlmsg_type) {
	case NL_RTM_NEWLINK:
	case NL_RTM_DELLINK:
	case NL_RTM_GETLINK:
		switch (nla->nla_type) {
		case IFLA_IFNAME:
			return (nlmsg_translate_ifname_nla(nla, nw));
		default:
			break;
		}
	default:
		break;
	}
	return (LINUX_NLA_UNHANDLED);
}

static bool
nlmsg_copy_all_nla(struct nlmsghdr *hdr, int raw_hdrlen, struct nl_writer *nw)
{
	struct nlattr *nla;
	int ret;

	int hdrlen = NETLINK_ALIGN(raw_hdrlen);
	int attrs_len = hdr->nlmsg_len - sizeof(struct nlmsghdr) - hdrlen;
	struct nlattr *nla_head = (struct nlattr *)((char *)(hdr + 1) + hdrlen);

	NLA_FOREACH(nla, nla_head, attrs_len) {
		RT_LOG(LOG_DEBUG3, "reading attr %d len %d", nla->nla_type, nla->nla_len);
		if (nla->nla_len < sizeof(struct nlattr)) {
			return (false);
		}
		ret = nlmsg_translate_all_nla(hdr, nla, nw);
		if (ret == LINUX_NLA_UNHANDLED)
			ret = nlmsg_copy_nla(nla, nw);
		if (!ret)
			return (false);
	}
	return (true);
}
#undef LINUX_NLA_UNHANDLED

static unsigned int
rtnl_if_flags_to_linux(unsigned int if_flags)
{
	unsigned int result = 0;

	for (int i = 0; i < 31; i++) {
		unsigned int flag = 1 << i;
		if (!(flag & if_flags))
			continue;
		switch (flag) {
		case IFF_UP:
		case IFF_BROADCAST:
		case IFF_DEBUG:
		case IFF_LOOPBACK:
		case IFF_POINTOPOINT:
		case IFF_DRV_RUNNING:
		case IFF_NOARP:
		case IFF_PROMISC:
		case IFF_ALLMULTI:
			result |= flag;
			break;
		case IFF_NEEDSEPOCH:
		case IFF_DRV_OACTIVE:
		case IFF_SIMPLEX:
		case IFF_LINK0:
		case IFF_LINK1:
		case IFF_LINK2:
		case IFF_CANTCONFIG:
		case IFF_PPROMISC:
		case IFF_MONITOR:
		case IFF_STATICARP:
		case IFF_STICKYARP:
		case IFF_DYING:
		case IFF_RENAMING:
			/* No Linux analogue */
			break;
		case IFF_MULTICAST:
			result |= 1 << 12;
		}
	}
	return (result);
}

static bool
rtnl_newlink_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp,
    struct nl_writer *nw)
{
	if (!nlmsg_copy_header(hdr, nw))
		return (false);

	struct ifinfomsg *ifinfo;
	ifinfo = nlmsg_copy_next_header(hdr, nw, struct ifinfomsg);

	ifinfo->ifi_family = bsd_to_linux_domain(ifinfo->ifi_family);
	/* Convert interface type */
	switch (ifinfo->ifi_type) {
	case IFT_ETHER:
		ifinfo->ifi_type = LINUX_ARPHRD_ETHER;
		break;
	}
	ifinfo->ifi_flags = rtnl_if_flags_to_linux(ifinfo->ifi_flags);

	/* Copy attributes unchanged */
	if (!nlmsg_copy_all_nla(hdr, sizeof(struct ifinfomsg), nw))
		return (false);

	/* make ip(8) happy */
	if (!nlattr_add_string(nw, IFLA_QDISC, "noqueue"))
		return (false);

	if (!nlattr_add_u32(nw, IFLA_TXQLEN, 1000))
		return (false);

	nlmsg_end(nw);
	RT_LOG(LOG_DEBUG2, "done processing nw %p", nw);
	return (true);
}

static bool
rtnl_newaddr_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp,
    struct nl_writer *nw)
{
	if (!nlmsg_copy_header(hdr, nw))
		return (false);

	struct ifaddrmsg *ifamsg;
	ifamsg = nlmsg_copy_next_header(hdr, nw, struct ifaddrmsg);

	ifamsg->ifa_family = bsd_to_linux_domain(ifamsg->ifa_family);
	/* XXX: fake ifa_flags? */

	/* Copy attributes unchanged */
	if (!nlmsg_copy_all_nla(hdr, sizeof(struct ifaddrmsg), nw))
		return (false);

	nlmsg_end(nw);
	RT_LOG(LOG_DEBUG2, "done processing nw %p", nw);
	return (true);
}

static bool
rtnl_newneigh_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp,
    struct nl_writer *nw)
{
	if (!nlmsg_copy_header(hdr, nw))
		return (false);

	struct ndmsg *ndm;
	ndm = nlmsg_copy_next_header(hdr, nw, struct ndmsg);

	ndm->ndm_family = bsd_to_linux_domain(ndm->ndm_family);

	/* Copy attributes unchanged */
	if (!nlmsg_copy_all_nla(hdr, sizeof(struct ndmsg), nw))
		return (false);

	nlmsg_end(nw);
	RT_LOG(LOG_DEBUG2, "done processing nw %p", nw);
	return (true);
}

static bool
rtnl_newroute_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp,
    struct nl_writer *nw)
{
	if (!nlmsg_copy_header(hdr, nw))
		return (false);

	struct rtmsg *rtm;
	rtm = nlmsg_copy_next_header(hdr, nw, struct rtmsg);
	rtm->rtm_family = bsd_to_linux_domain(rtm->rtm_family);

	struct nlattr *nla;

	int hdrlen = NETLINK_ALIGN(sizeof(struct rtmsg));
	int attrs_len = hdr->nlmsg_len - sizeof(struct nlmsghdr) - hdrlen;
	struct nlattr *nla_head = (struct nlattr *)((char *)(hdr + 1) + hdrlen);

	NLA_FOREACH(nla, nla_head, attrs_len) {
		struct rtattr *rta = (struct rtattr *)nla;
		//RT_LOG(LOG_DEBUG, "READING attr %d len %d", nla->nla_type, nla->nla_len);
		if (rta->rta_len < sizeof(struct rtattr)) {
			break;
		}

		switch (rta->rta_type) {
		case NL_RTA_TABLE:
			{
				uint32_t fibnum;
				fibnum = _rta_get_uint32(rta);
				if (fibnum == 0)
					fibnum = 254;
				RT_LOG(LOG_DEBUG3, "XFIBNUM %u", fibnum);
				if (!nlattr_add_u32(nw, NL_RTA_TABLE, fibnum))
					return (false);
			}
			break;
		default:
			if (!nlmsg_copy_nla(nla, nw))
				return (false);
			break;
		}
	}

	nlmsg_end(nw);
	RT_LOG(LOG_DEBUG2, "done processing nw %p", nw);
	return (true);
}

static bool
rtnl_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_writer *nw)
{
	RT_LOG(LOG_DEBUG2, "Got message type %d", hdr->nlmsg_type);

	switch (hdr->nlmsg_type) {
	case NL_RTM_NEWLINK:
	case NL_RTM_DELLINK:
	case NL_RTM_GETLINK:
		return (rtnl_newlink_to_linux(hdr, nlp, nw));
	case NL_RTM_NEWADDR:
	case NL_RTM_DELADDR:
		return (rtnl_newaddr_to_linux(hdr, nlp, nw));
	case NL_RTM_NEWROUTE:
	case NL_RTM_DELROUTE:
		return (rtnl_newroute_to_linux(hdr, nlp, nw));
	case NL_RTM_NEWNEIGH:
	case NL_RTM_DELNEIGH:
	case NL_RTM_GETNEIGH:
		return (rtnl_newneigh_to_linux(hdr, nlp, nw));
	default:
		RT_LOG(LOG_DEBUG, "[WARN] Passing message type %d untranslated",
		    hdr->nlmsg_type);
		return (handle_default_out(hdr, nw));
	}
}

static bool
nlmsg_error_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_writer *nw)
{
	if (!nlmsg_copy_header(hdr, nw))
		return (false);

	struct nlmsgerr *nlerr;
	nlerr = nlmsg_copy_next_header(hdr, nw, struct nlmsgerr);
	nlerr->error = bsd_to_linux_errno(nlerr->error);

	int copied_len = sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr);
	if (hdr->nlmsg_len == copied_len) {
		nlmsg_end(nw);
		return (true);
	}

	/*
	 * CAP_ACK was not set. Original request needs to be translated.
	 * XXX: implement translation of the original message
	 */
	RT_LOG(LOG_DEBUG, "[WARN] Passing ack message type %d untranslated",
	    nlerr->msg.nlmsg_type);
	char *dst_payload, *src_payload;
	int copy_len = hdr->nlmsg_len - copied_len;
	dst_payload = nlmsg_reserve_data(nw, NLMSG_ALIGN(copy_len), char);

	src_payload = (char *)hdr + copied_len;

	memcpy(dst_payload, src_payload, copy_len);
	nlmsg_end(nw);

	return (true);
}

static bool
nlmsg_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_writer *nw)
{
	if (hdr->nlmsg_type < NLMSG_MIN_TYPE) {
		switch (hdr->nlmsg_type) {
		case NLMSG_ERROR:
			return (nlmsg_error_to_linux(hdr, nlp, nw));
		case NLMSG_NOOP:
		case NLMSG_DONE:
		case NLMSG_OVERRUN:
			return (handle_default_out(hdr, nw));
		default:
			RT_LOG(LOG_DEBUG, "[WARN] Passing message type %d untranslated",
			    hdr->nlmsg_type);
			return (handle_default_out(hdr, nw));
		}
	}

	switch (nlp->nl_proto) {
	case NETLINK_ROUTE:
		return (rtnl_to_linux(hdr, nlp, nw));
	default:
		return (handle_default_out(hdr, nw));
	}
}

static struct nl_buf *
nlmsgs_to_linux(struct nl_buf *orig, struct nlpcb *nlp, const struct ifnet *ifp)
{
	struct nl_writer nw;
	u_int offset, msglen;

	if (__predict_false(!nl_writer_unicast(&nw,
	    orig->datalen + SCRATCH_BUFFER_SIZE, nlp, false)))
		return (NULL);

	nw.ifp = ifp;
	/* Assume correct headers. Buffer IS mutable */
	for (offset = 0;
	    offset + sizeof(struct nlmsghdr) <= orig->datalen;
	    offset += msglen) {
		struct nlmsghdr *hdr = (struct nlmsghdr *)&orig->data[offset];

		msglen = NLMSG_ALIGN(hdr->nlmsg_len);
		if (!nlmsg_to_linux(hdr, nlp, &nw)) {
			RT_LOG(LOG_DEBUG, "failed to process msg type %d",
			    hdr->nlmsg_type);
			nl_buf_free(nw.buf);
			return (NULL);
		}
	}

	RT_LOG(LOG_DEBUG3, "%p: in %u bytes %u messages", __func__,
	    nw.buf->datalen, nw.num_messages);

	return (nw.buf);
}

static struct linux_netlink_provider linux_netlink_v1 = {
	.msgs_to_linux = nlmsgs_to_linux,
	.msg_from_linux = nlmsg_from_linux,
};

void
linux_netlink_register(void)
{
	linux_netlink_p = &linux_netlink_v1;
}

void
linux_netlink_deregister(void)
{
	linux_netlink_p = NULL;
}