]>
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};
61 /* missing support for ES-IS on Solaris */
62 static const uint8_t ALL_ESS
[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04};
65 static uint8_t sock_buff
[8192];
67 static unsigned short pf_filter
[] = {
68 ENF_PUSHWORD
+ 0, /* Get the SSAP/DSAP values */
69 ENF_PUSHLIT
| ENF_CAND
, /* Check them */
70 ISO_SAP
| (ISO_SAP
<< 8),
71 ENF_PUSHWORD
+ 1, /* Get the control value */
72 ENF_PUSHLIT
| ENF_AND
, /* Isolate it */
78 ENF_PUSHLIT
| ENF_CAND
, /* Test for expected value */
87 * We would like to use something like libdlpi here, but that's not present on
88 * all versions of Solaris or on any non-Solaris system, so it's nowhere near
89 * as portable as we'd like. Thus, we use the standards-conformant DLPI
90 * interfaces plus the (optional; not needed) Solaris packet filter module.
93 static int dlpisend(int fd
, const void *cbuf
, size_t cbuflen
, const void *dbuf
,
94 size_t dbuflen
, int flags
)
96 const struct strbuf
*ctlptr
= NULL
;
97 const struct strbuf
*dataptr
= NULL
;
98 struct strbuf ctlbuf
, databuf
;
102 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
103 ctlbuf
.len
= cbuflen
;
104 ctlbuf
.buf
= (void *)cbuf
;
109 memset(&databuf
, 0, sizeof(databuf
));
110 databuf
.len
= dbuflen
;
111 databuf
.buf
= (void *)dbuf
;
115 /* We assume this doesn't happen often and isn't operationally
117 rv
= putmsg(fd
, ctlptr
, dataptr
, flags
);
118 if (rv
== -1 && dbuf
== NULL
) {
120 * For actual PDU transmission - recognizable buf dbuf != NULL,
121 * the error is passed upwards and should not be printed here.
123 zlog_debug("%s: putmsg: %s", __func__
, safe_strerror(errno
));
128 static ssize_t
dlpirctl(int fd
)
130 struct pollfd fds
[1];
131 struct strbuf ctlbuf
, databuf
;
135 /* Poll is used here in case the device doesn't speak DLPI
137 memset(fds
, 0, sizeof(fds
));
139 fds
[0].events
= POLLIN
| POLLPRI
;
140 if (poll(fds
, 1, 1000) <= 0)
143 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
144 memset(&databuf
, 0, sizeof(databuf
));
145 ctlbuf
.maxlen
= sizeof(dlpi_ctl
);
146 ctlbuf
.buf
= (void *)dlpi_ctl
;
147 databuf
.maxlen
= sizeof(sock_buff
);
148 databuf
.buf
= (void *)sock_buff
;
150 retv
= getmsg(fd
, &ctlbuf
, &databuf
, &flags
);
154 } while (ctlbuf
.len
== 0);
156 if (!(retv
& MORECTL
)) {
157 while (retv
& MOREDATA
) {
159 retv
= getmsg(fd
, NULL
, &databuf
, &flags
);
164 while (retv
& MORECTL
) {
166 retv
= getmsg(fd
, &ctlbuf
, &databuf
, &flags
);
171 static int dlpiok(int fd
, t_uscalar_t oprim
)
174 dl_ok_ack_t
*doa
= (dl_ok_ack_t
*)dlpi_ctl
;
177 if (retv
< (ssize_t
)DL_OK_ACK_SIZE
|| doa
->dl_primitive
!= DL_OK_ACK
178 || doa
->dl_correct_primitive
!= oprim
) {
185 static int dlpiinfo(int fd
)
190 memset(&dir
, 0, sizeof(dir
));
191 dir
.dl_primitive
= DL_INFO_REQ
;
192 /* Info_req uses M_PCPROTO. */
193 dlpisend(fd
, &dir
, sizeof(dir
), NULL
, 0, RS_HIPRI
);
195 if (retv
< (ssize_t
)DL_INFO_ACK_SIZE
|| dlpi_ctl
[0] != DL_INFO_ACK
)
201 static int dlpiopen(const char *devpath
, ssize_t
*acklen
)
205 fd
= open(devpath
, O_RDWR
| O_NONBLOCK
| O_NOCTTY
);
209 /* All that we want is for the open itself to be non-blocking, not I/O.
211 flags
= fcntl(fd
, F_GETFL
, 0);
213 fcntl(fd
, F_SETFL
, flags
& ~O_NONBLOCK
);
215 /* After opening, ask for information */
216 if ((*acklen
= dlpiinfo(fd
)) == -1) {
224 static int dlpiattach(int fd
, int unit
)
228 memset(&dar
, 0, sizeof(dar
));
229 dar
.dl_primitive
= DL_ATTACH_REQ
;
231 dlpisend(fd
, &dar
, sizeof(dar
), NULL
, 0, 0);
232 return dlpiok(fd
, dar
.dl_primitive
);
235 static int dlpibind(int fd
)
239 dl_bind_ack_t
*dba
= (dl_bind_ack_t
*)dlpi_ctl
;
241 memset(&dbr
, 0, sizeof(dbr
));
242 dbr
.dl_primitive
= DL_BIND_REQ
;
243 dbr
.dl_service_mode
= DL_CLDLS
;
244 dlpisend(fd
, &dbr
, sizeof(dbr
), NULL
, 0, 0);
247 if (retv
< (ssize_t
)DL_BIND_ACK_SIZE
248 || dba
->dl_primitive
!= DL_BIND_ACK
)
254 static int dlpimcast(int fd
, const uint8_t *mcaddr
)
257 dl_enabmulti_req_t der
;
258 uint8_t addr
[ETHERADDRL
];
261 memset(&dler
, 0, sizeof(dler
));
262 dler
.der
.dl_primitive
= DL_ENABMULTI_REQ
;
263 dler
.der
.dl_addr_length
= sizeof(dler
.addr
);
264 dler
.der
.dl_addr_offset
= dler
.addr
- (uint8_t *)&dler
;
265 memcpy(dler
.addr
, mcaddr
, sizeof(dler
.addr
));
266 dlpisend(fd
, &dler
, sizeof(dler
), NULL
, 0, 0);
267 return dlpiok(fd
, dler
.der
.dl_primitive
);
270 static int dlpiaddr(int fd
, uint8_t *addr
)
272 dl_phys_addr_req_t dpar
;
273 dl_phys_addr_ack_t
*dpaa
= (dl_phys_addr_ack_t
*)dlpi_ctl
;
276 memset(&dpar
, 0, sizeof(dpar
));
277 dpar
.dl_primitive
= DL_PHYS_ADDR_REQ
;
278 dpar
.dl_addr_type
= DL_CURR_PHYS_ADDR
;
279 dlpisend(fd
, &dpar
, sizeof(dpar
), NULL
, 0, 0);
282 if (retv
< (ssize_t
)DL_PHYS_ADDR_ACK_SIZE
283 || dpaa
->dl_primitive
!= DL_PHYS_ADDR_ACK
)
286 if (dpaa
->dl_addr_offset
< DL_PHYS_ADDR_ACK_SIZE
287 || dpaa
->dl_addr_length
!= ETHERADDRL
288 || dpaa
->dl_addr_offset
+ dpaa
->dl_addr_length
> (size_t)retv
)
291 bcopy((char *)dpaa
+ dpaa
->dl_addr_offset
, addr
, ETHERADDRL
);
295 static int open_dlpi_dev(struct isis_circuit
*circuit
)
297 int fd
= -1, unit
, retval
;
298 char devpath
[MAXPATHLEN
];
299 dl_info_ack_t
*dia
= (dl_info_ack_t
*)dlpi_ctl
;
302 /* Only broadcast-type are supported at the moment */
303 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
304 zlog_warn("%s: non-broadcast interface %s", __func__
,
305 circuit
->interface
->name
);
309 /* Try the vanity node first, if permitted */
310 if (getenv("DLPI_DEVONLY") == NULL
) {
311 (void)snprintf(devpath
, sizeof(devpath
), "/dev/net/%s",
312 circuit
->interface
->name
);
313 fd
= dlpiopen(devpath
, &acklen
);
316 /* Now try as an ordinary Style 1 node */
318 (void)snprintf(devpath
, sizeof(devpath
), "/dev/%s",
319 circuit
->interface
->name
);
321 fd
= dlpiopen(devpath
, &acklen
);
324 /* If that fails, try again as Style 2 */
328 cp
= devpath
+ strlen(devpath
);
329 while (--cp
>= devpath
&& isdigit(*cp
))
331 unit
= strtol(cp
, NULL
, 0);
333 fd
= dlpiopen(devpath
, &acklen
);
335 /* If that too fails, then the device really doesn't exist */
337 zlog_warn("%s: unknown interface %s", __func__
,
338 circuit
->interface
->name
);
342 /* Double check the DLPI style */
343 if (dia
->dl_provider_style
!= DL_STYLE2
) {
345 "open_dlpi_dev(): interface %s: %s is not style 2",
346 circuit
->interface
->name
, devpath
);
351 /* If it succeeds, then we need to attach to the unit specified
353 dlpiattach(fd
, unit
);
355 /* Reget the information, as it may be different per node */
356 if ((acklen
= dlpiinfo(fd
)) == -1) {
361 /* Double check the DLPI style */
362 if (dia
->dl_provider_style
!= DL_STYLE1
) {
364 "open_dlpi_dev(): interface %s: %s is not style 1",
365 circuit
->interface
->name
, devpath
);
371 /* Check that the interface we've got is the kind we expect */
372 if ((dia
->dl_sap_length
!= 2 && dia
->dl_sap_length
!= -2)
373 || dia
->dl_service_mode
!= DL_CLDLS
374 || dia
->dl_addr_length
!= ETHERADDRL
+ 2
375 || dia
->dl_brdcst_addr_length
!= ETHERADDRL
) {
376 zlog_warn("%s: unsupported interface type for %s", __func__
,
377 circuit
->interface
->name
);
381 switch (dia
->dl_mac_type
) {
390 zlog_warn("%s: unexpected mac type on %s: %lld", __func__
,
391 circuit
->interface
->name
,
392 (long long)dia
->dl_mac_type
);
397 circuit
->sap_length
= dia
->dl_sap_length
;
400 * The local hardware address is something that should be provided by
402 * sockaddr_dl for the interface, but isn't on Solaris. We set it here
404 * on DLPI's reported address to avoid roto-tilling the world.
405 * (Note that isis_circuit_if_add on Solaris doesn't set the snpa.)
407 * Unfortunately, GLD is broken and doesn't provide the address after
409 * so we need to be careful and use DL_PHYS_ADDR_REQ instead.
411 if (dlpiaddr(fd
, circuit
->u
.bc
.snpa
) == -1) {
413 "open_dlpi_dev(): interface %s: unable to get MAC address",
414 circuit
->interface
->name
);
419 /* Now bind to SAP 0. This gives us 802-type traffic. */
420 if (dlpibind(fd
) == -1) {
421 zlog_warn("%s: cannot bind SAP 0 on %s", __func__
,
422 circuit
->interface
->name
);
428 * Join to multicast groups according to
429 * 8.4.2 - Broadcast subnetwork IIH PDUs
432 retval
|= dlpimcast(fd
, ALL_L1_ISS
);
433 retval
|= dlpimcast(fd
, ALL_ISS
);
434 retval
|= dlpimcast(fd
, ALL_L2_ISS
);
437 zlog_warn("%s: unable to join multicast on %s", __func__
,
438 circuit
->interface
->name
);
443 /* Push on the packet filter to avoid stray 802 packets */
444 if (ioctl(fd
, I_PUSH
, "pfmod") == 0) {
445 struct packetfilt pfil
;
446 struct strioctl sioc
;
448 pfil
.Pf_Priority
= 0;
449 pfil
.Pf_FilterLen
= array_size(pf_filter
);
450 memcpy(pfil
.Pf_Filter
, pf_filter
, sizeof(pf_filter
));
451 /* pfmod does not support transparent ioctls */
452 sioc
.ic_cmd
= PFIOCSETF
;
454 sioc
.ic_len
= sizeof(struct packetfilt
);
455 sioc
.ic_dp
= (char *)&pfil
;
456 if (ioctl(fd
, I_STR
, &sioc
) == -1)
457 zlog_warn("%s: could not perform PF_IOCSETF on %s",
458 __func__
, circuit
->interface
->name
);
467 * Create the socket and set the tx/rx funcs
469 int isis_sock_init(struct isis_circuit
*circuit
)
471 int retval
= ISIS_OK
;
473 frr_with_privs(&isisd_privs
) {
475 retval
= open_dlpi_dev(circuit
);
477 if (retval
!= ISIS_OK
) {
478 zlog_warn("%s: could not initialize the socket",
483 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
484 circuit
->tx
= isis_send_pdu_bcast
;
485 circuit
->rx
= isis_recv_pdu_bcast
;
487 zlog_warn("isis_sock_init(): unknown circuit type");
488 retval
= ISIS_WARNING
;
496 int isis_recv_pdu_bcast(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
498 struct pollfd fds
[1];
499 struct strbuf ctlbuf
, databuf
;
501 dl_unitdata_ind_t
*dui
= (dl_unitdata_ind_t
*)dlpi_ctl
;
503 memset(fds
, 0, sizeof(fds
));
504 fds
[0].fd
= circuit
->fd
;
505 fds
[0].events
= POLLIN
| POLLPRI
;
506 if (poll(fds
, 1, 0) <= 0)
509 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
510 memset(&databuf
, 0, sizeof(databuf
));
511 ctlbuf
.maxlen
= sizeof(dlpi_ctl
);
512 ctlbuf
.buf
= (void *)dlpi_ctl
;
513 databuf
.maxlen
= sizeof(sock_buff
);
514 databuf
.buf
= (void *)sock_buff
;
516 retv
= getmsg(circuit
->fd
, &ctlbuf
, &databuf
, &flags
);
519 zlog_warn("isis_recv_pdu_bcast: getmsg failed: %s",
520 safe_strerror(errno
));
524 if (retv
& (MORECTL
| MOREDATA
)) {
525 while (retv
& (MORECTL
| MOREDATA
)) {
527 retv
= getmsg(circuit
->fd
, &ctlbuf
, &databuf
, &flags
);
532 if (ctlbuf
.len
< (ssize_t
)DL_UNITDATA_IND_SIZE
533 || dui
->dl_primitive
!= DL_UNITDATA_IND
)
536 if (dui
->dl_src_addr_length
!= ETHERADDRL
+ 2
537 || dui
->dl_src_addr_offset
< DL_UNITDATA_IND_SIZE
538 || dui
->dl_src_addr_offset
+ dui
->dl_src_addr_length
539 > (size_t)ctlbuf
.len
)
543 (char *)dui
+ dui
->dl_src_addr_offset
544 + (circuit
->sap_length
> 0 ? circuit
->sap_length
: 0),
547 if (databuf
.len
< LLC_LEN
|| sock_buff
[0] != ISO_SAP
548 || sock_buff
[1] != ISO_SAP
|| sock_buff
[2] != 3)
551 stream_write(circuit
->rcv_stream
, sock_buff
+ LLC_LEN
,
552 databuf
.len
- LLC_LEN
);
553 stream_set_getp(circuit
->rcv_stream
, 0);
558 int isis_send_pdu_bcast(struct isis_circuit
*circuit
, int level
)
560 dl_unitdata_req_t
*dur
= (dl_unitdata_req_t
*)dlpi_ctl
;
562 unsigned short *dstsap
;
566 buflen
= stream_get_endp(circuit
->snd_stream
) + LLC_LEN
;
567 if ((size_t)buflen
> sizeof(sock_buff
)) {
569 "isis_send_pdu_bcast: sock_buff size %zu is less than "
570 "output pdu size %d on circuit %s",
571 sizeof(sock_buff
), buflen
, circuit
->interface
->name
);
575 stream_set_getp(circuit
->snd_stream
, 0);
577 memset(dur
, 0, sizeof(*dur
));
578 dur
->dl_primitive
= DL_UNITDATA_REQ
;
579 dur
->dl_dest_addr_length
= ETHERADDRL
+ 2;
580 dur
->dl_dest_addr_offset
= sizeof(*dur
);
582 dstaddr
= (char *)(dur
+ 1);
583 if (circuit
->sap_length
< 0) {
584 dstsap
= (unsigned short *)(dstaddr
+ ETHERADDRL
);
586 dstsap
= (unsigned short *)dstaddr
;
587 dstaddr
+= circuit
->sap_length
;
590 memcpy(dstaddr
, ALL_L1_ISS
, ETHERADDRL
);
592 memcpy(dstaddr
, ALL_L2_ISS
, ETHERADDRL
);
593 /* Note: DLPI SAP values are in host byte order */
596 sock_buff
[0] = ISO_SAP
;
597 sock_buff
[1] = ISO_SAP
;
599 memcpy(sock_buff
+ LLC_LEN
, circuit
->snd_stream
->data
,
600 stream_get_endp(circuit
->snd_stream
));
601 rv
= dlpisend(circuit
->fd
, dur
, sizeof(*dur
) + dur
->dl_dest_addr_length
,
602 sock_buff
, buflen
, 0);
604 zlog_warn("IS-IS dlpi: could not transmit packet on %s: %s",
605 circuit
->interface
->name
, safe_strerror(errno
));
606 if (ERRNO_IO_RETRY(errno
))
614 #endif /* ISIS_METHOD == ISIS_METHOD_DLPI */