]>
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
) {
340 "open_dlpi_dev(): interface %s: %s is not style 2",
341 circuit
->interface
->name
, devpath
);
346 /* If it succeeds, then we need to attach to the unit specified
348 dlpiattach(fd
, unit
);
350 /* Reget the information, as it may be different per node */
351 if ((acklen
= dlpiinfo(fd
)) == -1) {
356 /* Double check the DLPI style */
357 if (dia
->dl_provider_style
!= DL_STYLE1
) {
359 "open_dlpi_dev(): interface %s: %s is not style 1",
360 circuit
->interface
->name
, devpath
);
366 /* Check that the interface we've got is the kind we expect */
367 if ((dia
->dl_sap_length
!= 2 && dia
->dl_sap_length
!= -2)
368 || dia
->dl_service_mode
!= DL_CLDLS
369 || dia
->dl_addr_length
!= ETHERADDRL
+ 2
370 || dia
->dl_brdcst_addr_length
!= ETHERADDRL
) {
371 zlog_warn("%s: unsupported interface type for %s", __func__
,
372 circuit
->interface
->name
);
376 switch (dia
->dl_mac_type
) {
385 zlog_warn("%s: unexpected mac type on %s: %lld", __func__
,
386 circuit
->interface
->name
,
387 (long long)dia
->dl_mac_type
);
392 circuit
->sap_length
= dia
->dl_sap_length
;
395 * The local hardware address is something that should be provided by
397 * sockaddr_dl for the interface, but isn't on Solaris. We set it here
399 * on DLPI's reported address to avoid roto-tilling the world.
400 * (Note that isis_circuit_if_add on Solaris doesn't set the snpa.)
402 * Unfortunately, GLD is broken and doesn't provide the address after
404 * so we need to be careful and use DL_PHYS_ADDR_REQ instead.
406 if (dlpiaddr(fd
, circuit
->u
.bc
.snpa
) == -1) {
408 "open_dlpi_dev(): interface %s: unable to get MAC address",
409 circuit
->interface
->name
);
414 /* Now bind to SAP 0. This gives us 802-type traffic. */
415 if (dlpibind(fd
) == -1) {
416 zlog_warn("%s: cannot bind SAP 0 on %s", __func__
,
417 circuit
->interface
->name
);
423 * Join to multicast groups according to
424 * 8.4.2 - Broadcast subnetwork IIH PDUs
427 retval
|= dlpimcast(fd
, ALL_L1_ISS
);
428 retval
|= dlpimcast(fd
, ALL_ISS
);
429 retval
|= dlpimcast(fd
, ALL_L2_ISS
);
432 zlog_warn("%s: unable to join multicast on %s", __func__
,
433 circuit
->interface
->name
);
438 /* Push on the packet filter to avoid stray 802 packets */
439 if (ioctl(fd
, I_PUSH
, "pfmod") == 0) {
440 struct packetfilt pfil
;
441 struct strioctl sioc
;
443 pfil
.Pf_Priority
= 0;
444 pfil
.Pf_FilterLen
= array_size(pf_filter
);
445 memcpy(pfil
.Pf_Filter
, pf_filter
, sizeof(pf_filter
));
446 /* pfmod does not support transparent ioctls */
447 sioc
.ic_cmd
= PFIOCSETF
;
449 sioc
.ic_len
= sizeof(struct packetfilt
);
450 sioc
.ic_dp
= (char *)&pfil
;
451 if (ioctl(fd
, I_STR
, &sioc
) == -1)
452 zlog_warn("%s: could not perform PF_IOCSETF on %s",
453 __func__
, circuit
->interface
->name
);
462 * Create the socket and set the tx/rx funcs
464 int isis_sock_init(struct isis_circuit
*circuit
)
466 int retval
= ISIS_OK
;
468 frr_with_privs(&isisd_privs
) {
470 retval
= open_dlpi_dev(circuit
);
472 if (retval
!= ISIS_OK
) {
473 zlog_warn("%s: could not initialize the socket",
478 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
479 circuit
->tx
= isis_send_pdu_bcast
;
480 circuit
->rx
= isis_recv_pdu_bcast
;
482 zlog_warn("isis_sock_init(): unknown circuit type");
483 retval
= ISIS_WARNING
;
491 int isis_recv_pdu_bcast(struct isis_circuit
*circuit
, uint8_t *ssnpa
)
493 struct pollfd fds
[1];
494 struct strbuf ctlbuf
, databuf
;
496 dl_unitdata_ind_t
*dui
= (dl_unitdata_ind_t
*)dlpi_ctl
;
498 memset(fds
, 0, sizeof(fds
));
499 fds
[0].fd
= circuit
->fd
;
500 fds
[0].events
= POLLIN
| POLLPRI
;
501 if (poll(fds
, 1, 0) <= 0)
504 memset(&ctlbuf
, 0, sizeof(ctlbuf
));
505 memset(&databuf
, 0, sizeof(databuf
));
506 ctlbuf
.maxlen
= sizeof(dlpi_ctl
);
507 ctlbuf
.buf
= (void *)dlpi_ctl
;
508 databuf
.maxlen
= sizeof(sock_buff
);
509 databuf
.buf
= (void *)sock_buff
;
511 retv
= getmsg(circuit
->fd
, &ctlbuf
, &databuf
, &flags
);
514 zlog_warn("isis_recv_pdu_bcast: getmsg failed: %s",
515 safe_strerror(errno
));
519 if (retv
& (MORECTL
| MOREDATA
)) {
520 while (retv
& (MORECTL
| MOREDATA
)) {
522 retv
= getmsg(circuit
->fd
, &ctlbuf
, &databuf
, &flags
);
527 if (ctlbuf
.len
< (ssize_t
)DL_UNITDATA_IND_SIZE
528 || dui
->dl_primitive
!= DL_UNITDATA_IND
)
531 if (dui
->dl_src_addr_length
!= ETHERADDRL
+ 2
532 || dui
->dl_src_addr_offset
< DL_UNITDATA_IND_SIZE
533 || dui
->dl_src_addr_offset
+ dui
->dl_src_addr_length
534 > (size_t)ctlbuf
.len
)
538 (char *)dui
+ dui
->dl_src_addr_offset
539 + (circuit
->sap_length
> 0 ? circuit
->sap_length
: 0),
542 if (databuf
.len
< LLC_LEN
|| sock_buff
[0] != ISO_SAP
543 || sock_buff
[1] != ISO_SAP
|| sock_buff
[2] != 3)
546 stream_write(circuit
->rcv_stream
, sock_buff
+ LLC_LEN
,
547 databuf
.len
- LLC_LEN
);
548 stream_set_getp(circuit
->rcv_stream
, 0);
553 int isis_send_pdu_bcast(struct isis_circuit
*circuit
, int level
)
555 dl_unitdata_req_t
*dur
= (dl_unitdata_req_t
*)dlpi_ctl
;
557 unsigned short *dstsap
;
561 buflen
= stream_get_endp(circuit
->snd_stream
) + LLC_LEN
;
562 if ((size_t)buflen
> sizeof(sock_buff
)) {
564 "isis_send_pdu_bcast: sock_buff size %zu is less than output pdu size %d on circuit %s",
565 sizeof(sock_buff
), buflen
, circuit
->interface
->name
);
569 stream_set_getp(circuit
->snd_stream
, 0);
571 memset(dur
, 0, sizeof(*dur
));
572 dur
->dl_primitive
= DL_UNITDATA_REQ
;
573 dur
->dl_dest_addr_length
= ETHERADDRL
+ 2;
574 dur
->dl_dest_addr_offset
= sizeof(*dur
);
576 dstaddr
= (char *)(dur
+ 1);
577 if (circuit
->sap_length
< 0) {
578 dstsap
= (unsigned short *)(dstaddr
+ ETHERADDRL
);
580 dstsap
= (unsigned short *)dstaddr
;
581 dstaddr
+= circuit
->sap_length
;
584 memcpy(dstaddr
, ALL_L1_ISS
, ETHERADDRL
);
586 memcpy(dstaddr
, ALL_L2_ISS
, ETHERADDRL
);
587 /* Note: DLPI SAP values are in host byte order */
590 sock_buff
[0] = ISO_SAP
;
591 sock_buff
[1] = ISO_SAP
;
593 memcpy(sock_buff
+ LLC_LEN
, circuit
->snd_stream
->data
,
594 stream_get_endp(circuit
->snd_stream
));
595 rv
= dlpisend(circuit
->fd
, dur
, sizeof(*dur
) + dur
->dl_dest_addr_length
,
596 sock_buff
, buflen
, 0);
598 zlog_warn("IS-IS dlpi: could not transmit packet on %s: %s",
599 circuit
->interface
->name
, safe_strerror(errno
));
600 if (ERRNO_IO_RETRY(errno
))
608 #endif /* ISIS_METHOD == ISIS_METHOD_DLPI */