]>
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/dict.h"
42 #include "isisd/isis_constants.h"
43 #include "isisd/isis_common.h"
44 #include "isisd/isis_circuit.h"
45 #include "isisd/isis_flags.h"
46 #include "isisd/isisd.h"
47 #include "isisd/isis_network.h"
51 static t_uscalar_t dlpi_ctl
[1024]; /* DLPI control messages */
54 * Table 9 - Architectural constants for use with ISO 8802 subnetworks
58 uint8_t ALL_L1_ISS
[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14};
59 uint8_t ALL_L2_ISS
[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15};
60 uint8_t ALL_ISS
[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05};
61 uint8_t ALL_ESS
[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04};
63 static uint8_t sock_buff
[8192];
65 static unsigned short pf_filter
[] = {
66 ENF_PUSHWORD
+ 0, /* Get the SSAP/DSAP values */
67 ENF_PUSHLIT
| ENF_CAND
, /* Check them */
68 ISO_SAP
| (ISO_SAP
<< 8),
69 ENF_PUSHWORD
+ 1, /* Get the control value */
70 ENF_PUSHLIT
| ENF_AND
, /* Isolate it */
76 ENF_PUSHLIT
| ENF_CAND
, /* Test for expected value */
85 * We would like to use something like libdlpi here, but that's not present on
86 * all versions of Solaris or on any non-Solaris system, so it's nowhere near
87 * as portable as we'd like. Thus, we use the standards-conformant DLPI
88 * interfaces plus the (optional; not needed) Solaris packet filter module.
91 static int dlpisend(int fd
, const void *cbuf
, size_t cbuflen
, const void *dbuf
,
92 size_t dbuflen
, int flags
)
94 const struct strbuf
*ctlptr
= NULL
;
95 const struct strbuf
*dataptr
= NULL
;
96 struct strbuf ctlbuf
, databuf
;
100 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
101 ctlbuf
.len
= cbuflen
;
102 ctlbuf
.buf
= (void *)cbuf
;
107 memset(&databuf
, 0, sizeof(databuf
));
108 databuf
.len
= dbuflen
;
109 databuf
.buf
= (void *)dbuf
;
113 /* We assume this doesn't happen often and isn't operationally
115 rv
= putmsg(fd
, ctlptr
, dataptr
, flags
);
116 if (rv
== -1 && dbuf
== NULL
) {
118 * For actual PDU transmission - recognizable buf dbuf != NULL,
119 * the error is passed upwards and should not be printed here.
121 zlog_debug("%s: putmsg: %s", __func__
, safe_strerror(errno
));
126 static ssize_t
dlpirctl(int fd
)
128 struct pollfd fds
[1];
129 struct strbuf ctlbuf
, databuf
;
133 /* Poll is used here in case the device doesn't speak DLPI
135 memset(fds
, 0, sizeof(fds
));
137 fds
[0].events
= POLLIN
| POLLPRI
;
138 if (poll(fds
, 1, 1000) <= 0)
141 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
142 memset(&databuf
, 0, sizeof(databuf
));
143 ctlbuf
.maxlen
= sizeof(dlpi_ctl
);
144 ctlbuf
.buf
= (void *)dlpi_ctl
;
145 databuf
.maxlen
= sizeof(sock_buff
);
146 databuf
.buf
= (void *)sock_buff
;
148 retv
= getmsg(fd
, &ctlbuf
, &databuf
, &flags
);
152 } while (ctlbuf
.len
== 0);
154 if (!(retv
& MORECTL
)) {
155 while (retv
& MOREDATA
) {
157 retv
= getmsg(fd
, NULL
, &databuf
, &flags
);
162 while (retv
& MORECTL
) {
164 retv
= getmsg(fd
, &ctlbuf
, &databuf
, &flags
);
169 static int dlpiok(int fd
, t_uscalar_t oprim
)
172 dl_ok_ack_t
*doa
= (dl_ok_ack_t
*)dlpi_ctl
;
175 if (retv
< (ssize_t
)DL_OK_ACK_SIZE
|| doa
->dl_primitive
!= DL_OK_ACK
176 || doa
->dl_correct_primitive
!= oprim
) {
183 static int dlpiinfo(int fd
)
188 memset(&dir
, 0, sizeof(dir
));
189 dir
.dl_primitive
= DL_INFO_REQ
;
190 /* Info_req uses M_PCPROTO. */
191 dlpisend(fd
, &dir
, sizeof(dir
), NULL
, 0, RS_HIPRI
);
193 if (retv
< (ssize_t
)DL_INFO_ACK_SIZE
|| dlpi_ctl
[0] != DL_INFO_ACK
)
199 static int dlpiopen(const char *devpath
, ssize_t
*acklen
)
203 fd
= open(devpath
, O_RDWR
| O_NONBLOCK
| O_NOCTTY
);
207 /* All that we want is for the open itself to be non-blocking, not I/O.
209 flags
= fcntl(fd
, F_GETFL
, 0);
211 fcntl(fd
, F_SETFL
, flags
& ~O_NONBLOCK
);
213 /* After opening, ask for information */
214 if ((*acklen
= dlpiinfo(fd
)) == -1) {
222 static int dlpiattach(int fd
, int unit
)
226 memset(&dar
, 0, sizeof(dar
));
227 dar
.dl_primitive
= DL_ATTACH_REQ
;
229 dlpisend(fd
, &dar
, sizeof(dar
), NULL
, 0, 0);
230 return dlpiok(fd
, dar
.dl_primitive
);
233 static int dlpibind(int fd
)
237 dl_bind_ack_t
*dba
= (dl_bind_ack_t
*)dlpi_ctl
;
239 memset(&dbr
, 0, sizeof(dbr
));
240 dbr
.dl_primitive
= DL_BIND_REQ
;
241 dbr
.dl_service_mode
= DL_CLDLS
;
242 dlpisend(fd
, &dbr
, sizeof(dbr
), NULL
, 0, 0);
245 if (retv
< (ssize_t
)DL_BIND_ACK_SIZE
246 || dba
->dl_primitive
!= DL_BIND_ACK
)
252 static int dlpimcast(int fd
, const uint8_t *mcaddr
)
255 dl_enabmulti_req_t der
;
256 uint8_t addr
[ETHERADDRL
];
259 memset(&dler
, 0, sizeof(dler
));
260 dler
.der
.dl_primitive
= DL_ENABMULTI_REQ
;
261 dler
.der
.dl_addr_length
= sizeof(dler
.addr
);
262 dler
.der
.dl_addr_offset
= dler
.addr
- (uint8_t *)&dler
;
263 memcpy(dler
.addr
, mcaddr
, sizeof(dler
.addr
));
264 dlpisend(fd
, &dler
, sizeof(dler
), NULL
, 0, 0);
265 return dlpiok(fd
, dler
.der
.dl_primitive
);
268 static int dlpiaddr(int fd
, uint8_t *addr
)
270 dl_phys_addr_req_t dpar
;
271 dl_phys_addr_ack_t
*dpaa
= (dl_phys_addr_ack_t
*)dlpi_ctl
;
274 memset(&dpar
, 0, sizeof(dpar
));
275 dpar
.dl_primitive
= DL_PHYS_ADDR_REQ
;
276 dpar
.dl_addr_type
= DL_CURR_PHYS_ADDR
;
277 dlpisend(fd
, &dpar
, sizeof(dpar
), NULL
, 0, 0);
280 if (retv
< (ssize_t
)DL_PHYS_ADDR_ACK_SIZE
281 || dpaa
->dl_primitive
!= DL_PHYS_ADDR_ACK
)
284 if (dpaa
->dl_addr_offset
< DL_PHYS_ADDR_ACK_SIZE
285 || dpaa
->dl_addr_length
!= ETHERADDRL
286 || dpaa
->dl_addr_offset
+ dpaa
->dl_addr_length
> (size_t)retv
)
289 bcopy((char *)dpaa
+ dpaa
->dl_addr_offset
, addr
, ETHERADDRL
);
293 static int open_dlpi_dev(struct isis_circuit
*circuit
)
295 int fd
= -1, unit
, retval
;
296 char devpath
[MAXPATHLEN
];
297 dl_info_ack_t
*dia
= (dl_info_ack_t
*)dlpi_ctl
;
300 /* Only broadcast-type are supported at the moment */
301 if (circuit
->circ_type
!= CIRCUIT_T_BROADCAST
) {
302 zlog_warn("%s: non-broadcast interface %s", __func__
,
303 circuit
->interface
->name
);
307 /* Try the vanity node first, if permitted */
308 if (getenv("DLPI_DEVONLY") == NULL
) {
309 (void)snprintf(devpath
, sizeof(devpath
), "/dev/net/%s",
310 circuit
->interface
->name
);
311 fd
= dlpiopen(devpath
, &acklen
);
314 /* Now try as an ordinary Style 1 node */
316 (void)snprintf(devpath
, sizeof(devpath
), "/dev/%s",
317 circuit
->interface
->name
);
319 fd
= dlpiopen(devpath
, &acklen
);
322 /* If that fails, try again as Style 2 */
326 cp
= devpath
+ strlen(devpath
);
327 while (--cp
>= devpath
&& isdigit(*cp
))
329 unit
= strtol(cp
, NULL
, 0);
331 fd
= dlpiopen(devpath
, &acklen
);
333 /* If that too fails, then the device really doesn't exist */
335 zlog_warn("%s: unknown interface %s", __func__
,
336 circuit
->interface
->name
);
340 /* Double check the DLPI style */
341 if (dia
->dl_provider_style
!= DL_STYLE2
) {
343 "open_dlpi_dev(): interface %s: %s is not style 2",
344 circuit
->interface
->name
, devpath
);
349 /* If it succeeds, then we need to attach to the unit specified
351 dlpiattach(fd
, unit
);
353 /* Reget the information, as it may be different per node */
354 if ((acklen
= dlpiinfo(fd
)) == -1) {
359 /* Double check the DLPI style */
360 if (dia
->dl_provider_style
!= DL_STYLE1
) {
362 "open_dlpi_dev(): interface %s: %s is not style 1",
363 circuit
->interface
->name
, devpath
);
369 /* Check that the interface we've got is the kind we expect */
370 if ((dia
->dl_sap_length
!= 2 && dia
->dl_sap_length
!= -2)
371 || dia
->dl_service_mode
!= DL_CLDLS
372 || dia
->dl_addr_length
!= ETHERADDRL
+ 2
373 || dia
->dl_brdcst_addr_length
!= ETHERADDRL
) {
374 zlog_warn("%s: unsupported interface type for %s", __func__
,
375 circuit
->interface
->name
);
379 switch (dia
->dl_mac_type
) {
388 zlog_warn("%s: unexpected mac type on %s: %lld", __func__
,
389 circuit
->interface
->name
,
390 (long long)dia
->dl_mac_type
);
395 circuit
->sap_length
= dia
->dl_sap_length
;
398 * The local hardware address is something that should be provided by
400 * sockaddr_dl for the interface, but isn't on Solaris. We set it here
402 * on DLPI's reported address to avoid roto-tilling the world.
403 * (Note that isis_circuit_if_add on Solaris doesn't set the snpa.)
405 * Unfortunately, GLD is broken and doesn't provide the address after
407 * so we need to be careful and use DL_PHYS_ADDR_REQ instead.
409 if (dlpiaddr(fd
, circuit
->u
.bc
.snpa
) == -1) {
411 "open_dlpi_dev(): interface %s: unable to get MAC address",
412 circuit
->interface
->name
);
417 /* Now bind to SAP 0. This gives us 802-type traffic. */
418 if (dlpibind(fd
) == -1) {
419 zlog_warn("%s: cannot bind SAP 0 on %s", __func__
,
420 circuit
->interface
->name
);
426 * Join to multicast groups according to
427 * 8.4.2 - Broadcast subnetwork IIH PDUs
430 retval
|= dlpimcast(fd
, ALL_L1_ISS
);
431 retval
|= dlpimcast(fd
, ALL_ISS
);
432 retval
|= dlpimcast(fd
, ALL_L2_ISS
);
435 zlog_warn("%s: unable to join multicast on %s", __func__
,
436 circuit
->interface
->name
);
441 /* Push on the packet filter to avoid stray 802 packets */
442 if (ioctl(fd
, I_PUSH
, "pfmod") == 0) {
443 struct packetfilt pfil
;
444 struct strioctl sioc
;
446 pfil
.Pf_Priority
= 0;
447 pfil
.Pf_FilterLen
= array_size(pf_filter
);
448 memcpy(pfil
.Pf_Filter
, pf_filter
, sizeof(pf_filter
));
449 /* pfmod does not support transparent ioctls */
450 sioc
.ic_cmd
= PFIOCSETF
;
452 sioc
.ic_len
= sizeof(struct packetfilt
);
453 sioc
.ic_dp
= (char *)&pfil
;
454 if (ioctl(fd
, I_STR
, &sioc
) == -1)
455 zlog_warn("%s: could not perform PF_IOCSETF on %s",
456 __func__
, circuit
->interface
->name
);
465 * Create the socket and set the tx/rx funcs
467 int isis_sock_init(struct isis_circuit
*circuit
)
469 int retval
= ISIS_OK
;
471 frr_elevate_privs(&isisd_privs
) {
473 retval
= open_dlpi_dev(circuit
);
475 if (retval
!= ISIS_OK
) {
476 zlog_warn("%s: could not initialize the socket",
481 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
482 circuit
->tx
= isis_send_pdu_bcast
;
483 circuit
->rx
= isis_recv_pdu_bcast
;
485 zlog_warn("isis_sock_init(): unknown circuit type");
486 retval
= ISIS_WARNING
;
494 int isis_recv_pdu_bcast(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
496 struct pollfd fds
[1];
497 struct strbuf ctlbuf
, databuf
;
499 dl_unitdata_ind_t
*dui
= (dl_unitdata_ind_t
*)dlpi_ctl
;
501 memset(fds
, 0, sizeof(fds
));
502 fds
[0].fd
= circuit
->fd
;
503 fds
[0].events
= POLLIN
| POLLPRI
;
504 if (poll(fds
, 1, 0) <= 0)
507 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
508 memset(&databuf
, 0, sizeof(databuf
));
509 ctlbuf
.maxlen
= sizeof(dlpi_ctl
);
510 ctlbuf
.buf
= (void *)dlpi_ctl
;
511 databuf
.maxlen
= sizeof(sock_buff
);
512 databuf
.buf
= (void *)sock_buff
;
514 retv
= getmsg(circuit
->fd
, &ctlbuf
, &databuf
, &flags
);
517 zlog_warn("isis_recv_pdu_bcast: getmsg failed: %s",
518 safe_strerror(errno
));
522 if (retv
& (MORECTL
| MOREDATA
)) {
523 while (retv
& (MORECTL
| MOREDATA
)) {
525 retv
= getmsg(circuit
->fd
, &ctlbuf
, &databuf
, &flags
);
530 if (ctlbuf
.len
< (ssize_t
)DL_UNITDATA_IND_SIZE
531 || dui
->dl_primitive
!= DL_UNITDATA_IND
)
534 if (dui
->dl_src_addr_length
!= ETHERADDRL
+ 2
535 || dui
->dl_src_addr_offset
< DL_UNITDATA_IND_SIZE
536 || dui
->dl_src_addr_offset
+ dui
->dl_src_addr_length
537 > (size_t)ctlbuf
.len
)
541 (char *)dui
+ dui
->dl_src_addr_offset
542 + (circuit
->sap_length
> 0 ? circuit
->sap_length
: 0),
545 if (databuf
.len
< LLC_LEN
|| sock_buff
[0] != ISO_SAP
546 || sock_buff
[1] != ISO_SAP
|| sock_buff
[2] != 3)
549 stream_write(circuit
->rcv_stream
, sock_buff
+ LLC_LEN
,
550 databuf
.len
- LLC_LEN
);
551 stream_set_getp(circuit
->rcv_stream
, 0);
556 int isis_send_pdu_bcast(struct isis_circuit
*circuit
, int level
)
558 dl_unitdata_req_t
*dur
= (dl_unitdata_req_t
*)dlpi_ctl
;
560 unsigned short *dstsap
;
564 buflen
= stream_get_endp(circuit
->snd_stream
) + LLC_LEN
;
565 if ((size_t)buflen
> sizeof(sock_buff
)) {
567 "isis_send_pdu_bcast: sock_buff size %zu is less than "
568 "output pdu size %d on circuit %s",
569 sizeof(sock_buff
), buflen
, circuit
->interface
->name
);
573 stream_set_getp(circuit
->snd_stream
, 0);
575 memset(dur
, 0, sizeof(*dur
));
576 dur
->dl_primitive
= DL_UNITDATA_REQ
;
577 dur
->dl_dest_addr_length
= ETHERADDRL
+ 2;
578 dur
->dl_dest_addr_offset
= sizeof(*dur
);
580 dstaddr
= (char *)(dur
+ 1);
581 if (circuit
->sap_length
< 0) {
582 dstsap
= (unsigned short *)(dstaddr
+ ETHERADDRL
);
584 dstsap
= (unsigned short *)dstaddr
;
585 dstaddr
+= circuit
->sap_length
;
588 memcpy(dstaddr
, ALL_L1_ISS
, ETHERADDRL
);
590 memcpy(dstaddr
, ALL_L2_ISS
, ETHERADDRL
);
591 /* Note: DLPI SAP values are in host byte order */
594 sock_buff
[0] = ISO_SAP
;
595 sock_buff
[1] = ISO_SAP
;
597 memcpy(sock_buff
+ LLC_LEN
, circuit
->snd_stream
->data
,
598 stream_get_endp(circuit
->snd_stream
));
599 rv
= dlpisend(circuit
->fd
, dur
, sizeof(*dur
) + dur
->dl_dest_addr_length
,
600 sock_buff
, buflen
, 0);
602 zlog_warn("IS-IS dlpi: could not transmit packet on %s: %s",
603 circuit
->interface
->name
, safe_strerror(errno
));
604 if (ERRNO_IO_RETRY(errno
))
612 #endif /* ISIS_METHOD == ISIS_METHOD_DLPI */