]>
git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_dlpi.c
2 * IS-IS Rout(e)ing protocol - isis_dlpi.c
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public Licenseas published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
13 * This program is distributed in the hope that it will be useful,but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #if ISIS_METHOD == ISIS_METHOD_DLPI
26 #include <netinet/if_ether.h>
27 #include <sys/types.h>
33 #include <sys/pfmod.h>
39 #include "lib_errors.h"
41 #include "isisd/isis_constants.h"
42 #include "isisd/isis_common.h"
43 #include "isisd/isis_circuit.h"
44 #include "isisd/isis_flags.h"
45 #include "isisd/isisd.h"
46 #include "isisd/isis_network.h"
50 static t_uscalar_t dlpi_ctl
[1024]; /* DLPI control messages */
53 * Table 9 - Architectural constants for use with ISO 8802 subnetworks
57 static const uint8_t ALL_L1_ISS
[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14};
58 static const uint8_t ALL_L2_ISS
[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15};
59 static const uint8_t ALL_ISS
[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05};
60 static uint8_t sock_buff
[16384];
62 static unsigned short pf_filter
[] = {
63 ENF_PUSHWORD
+ 0, /* Get the SSAP/DSAP values */
64 ENF_PUSHLIT
| ENF_CAND
, /* Check them */
65 ISO_SAP
| (ISO_SAP
<< 8),
66 ENF_PUSHWORD
+ 1, /* Get the control value */
67 ENF_PUSHLIT
| ENF_AND
, /* Isolate it */
73 ENF_PUSHLIT
| ENF_CAND
, /* Test for expected value */
82 * We would like to use something like libdlpi here, but that's not present on
83 * all versions of Solaris or on any non-Solaris system, so it's nowhere near
84 * as portable as we'd like. Thus, we use the standards-conformant DLPI
85 * interfaces plus the (optional; not needed) Solaris packet filter module.
88 static int dlpisend(int fd
, const void *cbuf
, size_t cbuflen
, const void *dbuf
,
89 size_t dbuflen
, int flags
)
91 const struct strbuf
*ctlptr
= NULL
;
92 const struct strbuf
*dataptr
= NULL
;
93 struct strbuf ctlbuf
, databuf
;
97 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
99 ctlbuf
.buf
= (void *)cbuf
;
104 memset(&databuf
, 0, sizeof(databuf
));
105 databuf
.len
= dbuflen
;
106 databuf
.buf
= (void *)dbuf
;
110 /* We assume this doesn't happen often and isn't operationally
112 rv
= putmsg(fd
, ctlptr
, dataptr
, flags
);
113 if (rv
== -1 && dbuf
== NULL
) {
115 * For actual PDU transmission - recognizable buf dbuf != NULL,
116 * the error is passed upwards and should not be printed here.
118 zlog_debug("%s: putmsg: %s", __func__
, safe_strerror(errno
));
123 static ssize_t
dlpirctl(int fd
)
125 struct pollfd fds
[1];
126 struct strbuf ctlbuf
, databuf
;
130 /* Poll is used here in case the device doesn't speak DLPI
132 memset(fds
, 0, sizeof(fds
));
134 fds
[0].events
= POLLIN
| POLLPRI
;
135 if (poll(fds
, 1, 1000) <= 0)
138 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
139 memset(&databuf
, 0, sizeof(databuf
));
140 ctlbuf
.maxlen
= sizeof(dlpi_ctl
);
141 ctlbuf
.buf
= (void *)dlpi_ctl
;
142 databuf
.maxlen
= sizeof(sock_buff
);
143 databuf
.buf
= (void *)sock_buff
;
145 retv
= getmsg(fd
, &ctlbuf
, &databuf
, &flags
);
149 } while (ctlbuf
.len
== 0);
151 if (!(retv
& MORECTL
)) {
152 while (retv
& MOREDATA
) {
154 retv
= getmsg(fd
, NULL
, &databuf
, &flags
);
159 while (retv
& MORECTL
) {
161 retv
= getmsg(fd
, &ctlbuf
, &databuf
, &flags
);
166 static int dlpiok(int fd
, t_uscalar_t oprim
)
169 dl_ok_ack_t
*doa
= (dl_ok_ack_t
*)dlpi_ctl
;
172 if (retv
< (ssize_t
)DL_OK_ACK_SIZE
|| doa
->dl_primitive
!= DL_OK_ACK
173 || doa
->dl_correct_primitive
!= oprim
) {
180 static int dlpiinfo(int fd
)
185 memset(&dir
, 0, sizeof(dir
));
186 dir
.dl_primitive
= DL_INFO_REQ
;
187 /* Info_req uses M_PCPROTO. */
188 dlpisend(fd
, &dir
, sizeof(dir
), NULL
, 0, RS_HIPRI
);
190 if (retv
< (ssize_t
)DL_INFO_ACK_SIZE
|| dlpi_ctl
[0] != DL_INFO_ACK
)
196 static int dlpiopen(const char *devpath
, ssize_t
*acklen
)
200 fd
= open(devpath
, O_RDWR
| O_NONBLOCK
| O_NOCTTY
);
204 /* All that we want is for the open itself to be non-blocking, not I/O.
206 flags
= fcntl(fd
, F_GETFL
, 0);
208 fcntl(fd
, F_SETFL
, flags
& ~O_NONBLOCK
);
210 /* After opening, ask for information */
211 if ((*acklen
= dlpiinfo(fd
)) == -1) {
219 static int dlpiattach(int fd
, int unit
)
223 memset(&dar
, 0, sizeof(dar
));
224 dar
.dl_primitive
= DL_ATTACH_REQ
;
226 dlpisend(fd
, &dar
, sizeof(dar
), NULL
, 0, 0);
227 return dlpiok(fd
, dar
.dl_primitive
);
230 static int dlpibind(int fd
)
234 dl_bind_ack_t
*dba
= (dl_bind_ack_t
*)dlpi_ctl
;
236 memset(&dbr
, 0, sizeof(dbr
));
237 dbr
.dl_primitive
= DL_BIND_REQ
;
238 dbr
.dl_service_mode
= DL_CLDLS
;
239 dlpisend(fd
, &dbr
, sizeof(dbr
), NULL
, 0, 0);
242 if (retv
< (ssize_t
)DL_BIND_ACK_SIZE
243 || dba
->dl_primitive
!= DL_BIND_ACK
)
249 static int dlpimcast(int fd
, const uint8_t *mcaddr
)
252 dl_enabmulti_req_t der
;
253 uint8_t addr
[ETHERADDRL
];
256 memset(&dler
, 0, sizeof(dler
));
257 dler
.der
.dl_primitive
= DL_ENABMULTI_REQ
;
258 dler
.der
.dl_addr_length
= sizeof(dler
.addr
);
259 dler
.der
.dl_addr_offset
= dler
.addr
- (uint8_t *)&dler
;
260 memcpy(dler
.addr
, mcaddr
, sizeof(dler
.addr
));
261 dlpisend(fd
, &dler
, sizeof(dler
), NULL
, 0, 0);
262 return dlpiok(fd
, dler
.der
.dl_primitive
);
265 static int dlpiaddr(int fd
, uint8_t *addr
)
267 dl_phys_addr_req_t dpar
;
268 dl_phys_addr_ack_t
*dpaa
= (dl_phys_addr_ack_t
*)dlpi_ctl
;
271 memset(&dpar
, 0, sizeof(dpar
));
272 dpar
.dl_primitive
= DL_PHYS_ADDR_REQ
;
273 dpar
.dl_addr_type
= DL_CURR_PHYS_ADDR
;
274 dlpisend(fd
, &dpar
, sizeof(dpar
), NULL
, 0, 0);
277 if (retv
< (ssize_t
)DL_PHYS_ADDR_ACK_SIZE
278 || dpaa
->dl_primitive
!= DL_PHYS_ADDR_ACK
)
281 if (dpaa
->dl_addr_offset
< DL_PHYS_ADDR_ACK_SIZE
282 || dpaa
->dl_addr_length
!= ETHERADDRL
283 || dpaa
->dl_addr_offset
+ dpaa
->dl_addr_length
> (size_t)retv
)
286 bcopy((char *)dpaa
+ dpaa
->dl_addr_offset
, addr
, ETHERADDRL
);
290 static int open_dlpi_dev(struct isis_circuit
*circuit
)
292 int fd
= -1, unit
, retval
;
293 char devpath
[MAXPATHLEN
];
294 dl_info_ack_t
*dia
= (dl_info_ack_t
*)dlpi_ctl
;
297 /* Only broadcast-type are supported at the moment */
298 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
299 zlog_warn("%s: non-broadcast interface %s", __func__
,
300 circuit
->interface
->name
);
304 /* Try the vanity node first, if permitted */
305 if (getenv("DLPI_DEVONLY") == NULL
) {
306 (void)snprintf(devpath
, sizeof(devpath
), "/dev/net/%s",
307 circuit
->interface
->name
);
308 fd
= dlpiopen(devpath
, &acklen
);
311 /* Now try as an ordinary Style 1 node */
313 (void)snprintf(devpath
, sizeof(devpath
), "/dev/%s",
314 circuit
->interface
->name
);
316 fd
= dlpiopen(devpath
, &acklen
);
319 /* If that fails, try again as Style 2 */
323 cp
= devpath
+ strlen(devpath
);
324 while (--cp
>= devpath
&& isdigit(*cp
))
326 unit
= strtol(cp
, NULL
, 0);
328 fd
= dlpiopen(devpath
, &acklen
);
330 /* If that too fails, then the device really doesn't exist */
332 zlog_warn("%s: unknown interface %s", __func__
,
333 circuit
->interface
->name
);
337 /* Double check the DLPI style */
338 if (dia
->dl_provider_style
!= DL_STYLE2
) {
339 zlog_warn("%s: interface %s: %s is not style 2",
340 __func__
, circuit
->interface
->name
, devpath
);
345 /* If it succeeds, then we need to attach to the unit specified
347 dlpiattach(fd
, unit
);
349 /* Reget the information, as it may be different per node */
350 if ((acklen
= dlpiinfo(fd
)) == -1) {
355 /* Double check the DLPI style */
356 if (dia
->dl_provider_style
!= DL_STYLE1
) {
357 zlog_warn("%s: interface %s: %s is not style 1",
358 __func__
, circuit
->interface
->name
, devpath
);
364 /* Check that the interface we've got is the kind we expect */
365 if ((dia
->dl_sap_length
!= 2 && dia
->dl_sap_length
!= -2)
366 || dia
->dl_service_mode
!= DL_CLDLS
367 || dia
->dl_addr_length
!= ETHERADDRL
+ 2
368 || dia
->dl_brdcst_addr_length
!= ETHERADDRL
) {
369 zlog_warn("%s: unsupported interface type for %s", __func__
,
370 circuit
->interface
->name
);
374 switch (dia
->dl_mac_type
) {
383 zlog_warn("%s: unexpected mac type on %s: %lld", __func__
,
384 circuit
->interface
->name
,
385 (long long)dia
->dl_mac_type
);
390 circuit
->sap_length
= dia
->dl_sap_length
;
393 * The local hardware address is something that should be provided by
395 * sockaddr_dl for the interface, but isn't on Solaris. We set it here
397 * on DLPI's reported address to avoid roto-tilling the world.
398 * (Note that isis_circuit_if_add on Solaris doesn't set the snpa.)
400 * Unfortunately, GLD is broken and doesn't provide the address after
402 * so we need to be careful and use DL_PHYS_ADDR_REQ instead.
404 if (dlpiaddr(fd
, circuit
->u
.bc
.snpa
) == -1) {
405 zlog_warn("%s: interface %s: unable to get MAC address",
406 __func__
, circuit
->interface
->name
);
411 /* Now bind to SAP 0. This gives us 802-type traffic. */
412 if (dlpibind(fd
) == -1) {
413 zlog_warn("%s: cannot bind SAP 0 on %s", __func__
,
414 circuit
->interface
->name
);
420 * Join to multicast groups according to
421 * 8.4.2 - Broadcast subnetwork IIH PDUs
424 retval
|= dlpimcast(fd
, ALL_L1_ISS
);
425 retval
|= dlpimcast(fd
, ALL_ISS
);
426 retval
|= dlpimcast(fd
, ALL_L2_ISS
);
429 zlog_warn("%s: unable to join multicast on %s", __func__
,
430 circuit
->interface
->name
);
435 /* Push on the packet filter to avoid stray 802 packets */
436 if (ioctl(fd
, I_PUSH
, "pfmod") == 0) {
437 struct packetfilt pfil
;
438 struct strioctl sioc
;
440 pfil
.Pf_Priority
= 0;
441 pfil
.Pf_FilterLen
= array_size(pf_filter
);
442 memcpy(pfil
.Pf_Filter
, pf_filter
, sizeof(pf_filter
));
443 /* pfmod does not support transparent ioctls */
444 sioc
.ic_cmd
= PFIOCSETF
;
446 sioc
.ic_len
= sizeof(struct packetfilt
);
447 sioc
.ic_dp
= (char *)&pfil
;
448 if (ioctl(fd
, I_STR
, &sioc
) == -1)
449 zlog_warn("%s: could not perform PF_IOCSETF on %s",
450 __func__
, circuit
->interface
->name
);
459 * Create the socket and set the tx/rx funcs
461 int isis_sock_init(struct isis_circuit
*circuit
)
463 int retval
= ISIS_OK
;
465 frr_with_privs(&isisd_privs
) {
467 retval
= open_dlpi_dev(circuit
);
469 if (retval
!= ISIS_OK
) {
470 zlog_warn("%s: could not initialize the socket",
475 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
476 circuit
->tx
= isis_send_pdu_bcast
;
477 circuit
->rx
= isis_recv_pdu_bcast
;
479 zlog_warn("%s: unknown circuit type", __func__
);
480 retval
= ISIS_WARNING
;
488 int isis_recv_pdu_bcast(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
490 struct pollfd fds
[1];
491 struct strbuf ctlbuf
, databuf
;
493 dl_unitdata_ind_t
*dui
= (dl_unitdata_ind_t
*)dlpi_ctl
;
495 memset(fds
, 0, sizeof(fds
));
496 fds
[0].fd
= circuit
->fd
;
497 fds
[0].events
= POLLIN
| POLLPRI
;
498 if (poll(fds
, 1, 0) <= 0)
501 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
502 memset(&databuf
, 0, sizeof(databuf
));
503 ctlbuf
.maxlen
= sizeof(dlpi_ctl
);
504 ctlbuf
.buf
= (void *)dlpi_ctl
;
505 databuf
.maxlen
= sizeof(sock_buff
);
506 databuf
.buf
= (void *)sock_buff
;
508 retv
= getmsg(circuit
->fd
, &ctlbuf
, &databuf
, &flags
);
511 zlog_warn("%s: getmsg failed: %s", __func__
,
512 safe_strerror(errno
));
516 if (retv
& (MORECTL
| MOREDATA
)) {
517 while (retv
& (MORECTL
| MOREDATA
)) {
519 retv
= getmsg(circuit
->fd
, &ctlbuf
, &databuf
, &flags
);
524 if (ctlbuf
.len
< (ssize_t
)DL_UNITDATA_IND_SIZE
525 || dui
->dl_primitive
!= DL_UNITDATA_IND
)
528 if (dui
->dl_src_addr_length
!= ETHERADDRL
+ 2
529 || dui
->dl_src_addr_offset
< DL_UNITDATA_IND_SIZE
530 || dui
->dl_src_addr_offset
+ dui
->dl_src_addr_length
531 > (size_t)ctlbuf
.len
)
535 (char *)dui
+ dui
->dl_src_addr_offset
536 + (circuit
->sap_length
> 0 ? circuit
->sap_length
: 0),
539 if (databuf
.len
< LLC_LEN
|| sock_buff
[0] != ISO_SAP
540 || sock_buff
[1] != ISO_SAP
|| sock_buff
[2] != 3)
543 stream_write(circuit
->rcv_stream
, sock_buff
+ LLC_LEN
,
544 databuf
.len
- LLC_LEN
);
545 stream_set_getp(circuit
->rcv_stream
, 0);
550 int isis_send_pdu_bcast(struct isis_circuit
*circuit
, int level
)
552 dl_unitdata_req_t
*dur
= (dl_unitdata_req_t
*)dlpi_ctl
;
554 unsigned short *dstsap
;
558 buflen
= stream_get_endp(circuit
->snd_stream
) + LLC_LEN
;
559 if ((size_t)buflen
> sizeof(sock_buff
)) {
561 "%s: sock_buff size %zu is less than output pdu size %d on circuit %s",
562 __func__
, sizeof(sock_buff
), buflen
,
563 circuit
->interface
->name
);
567 stream_set_getp(circuit
->snd_stream
, 0);
569 memset(dur
, 0, sizeof(*dur
));
570 dur
->dl_primitive
= DL_UNITDATA_REQ
;
571 dur
->dl_dest_addr_length
= ETHERADDRL
+ 2;
572 dur
->dl_dest_addr_offset
= sizeof(*dur
);
574 dstaddr
= (char *)(dur
+ 1);
575 if (circuit
->sap_length
< 0) {
576 dstsap
= (unsigned short *)(dstaddr
+ ETHERADDRL
);
578 dstsap
= (unsigned short *)dstaddr
;
579 dstaddr
+= circuit
->sap_length
;
582 memcpy(dstaddr
, ALL_L1_ISS
, ETHERADDRL
);
584 memcpy(dstaddr
, ALL_L2_ISS
, ETHERADDRL
);
585 /* Note: DLPI SAP values are in host byte order */
588 sock_buff
[0] = ISO_SAP
;
589 sock_buff
[1] = ISO_SAP
;
591 memcpy(sock_buff
+ LLC_LEN
, circuit
->snd_stream
->data
,
592 stream_get_endp(circuit
->snd_stream
));
593 rv
= dlpisend(circuit
->fd
, dur
, sizeof(*dur
) + dur
->dl_dest_addr_length
,
594 sock_buff
, buflen
, 0);
596 zlog_warn("IS-IS dlpi: could not transmit packet on %s: %s",
597 circuit
->interface
->name
, safe_strerror(errno
));
598 if (ERRNO_IO_RETRY(errno
))
606 #endif /* ISIS_METHOD == ISIS_METHOD_DLPI */