| version 1.1.1.2, 2012/10/09 09:22:28 | version 1.1.1.4, 2016/11/02 10:09:10 | 
| Line 26 | Line 26 | 
 | #include <netpacket/packet.h> | #include <netpacket/packet.h> | 
 |  |  | 
 | #include "log.h" | #include "log.h" | 
 |  | #include "network.h" | 
 | #include "stream.h" | #include "stream.h" | 
 | #include "if.h" | #include "if.h" | 
 |  |  | 
| Line 54  u_char ALL_L2_ISS[6] = { 0x01, 0x80, 0xC2, 0x00, 0x00, | Line 55  u_char ALL_L2_ISS[6] = { 0x01, 0x80, 0xC2, 0x00, 0x00, | 
 | u_char ALL_ISS[6] = { 0x09, 0x00, 0x2B, 0x00, 0x00, 0x05 }; | u_char ALL_ISS[6] = { 0x09, 0x00, 0x2B, 0x00, 0x00, 0x05 }; | 
 | u_char ALL_ESS[6] = { 0x09, 0x00, 0x2B, 0x00, 0x00, 0x04 }; | u_char ALL_ESS[6] = { 0x09, 0x00, 0x2B, 0x00, 0x00, 0x04 }; | 
 |  |  | 
| static char discard_buff[8192]; | static uint8_t discard_buff[8192]; | 
| static char sock_buff[8192]; | static uint8_t sock_buff[8192]; | 
 |  |  | 
 | /* | /* | 
 | * if level is 0 we are joining p2p multicast | * if level is 0 we are joining p2p multicast | 
| Line 129  open_packet_socket (struct isis_circuit *circuit) | Line 130  open_packet_socket (struct isis_circuit *circuit) | 
 | sizeof (struct sockaddr_ll)) < 0) | sizeof (struct sockaddr_ll)) < 0) | 
 | { | { | 
 | zlog_warn ("open_packet_socket(): bind() failed: %s", safe_strerror (errno)); | zlog_warn ("open_packet_socket(): bind() failed: %s", safe_strerror (errno)); | 
 |  | close (fd); | 
 | return ISIS_WARNING; | return ISIS_WARNING; | 
 | } | } | 
 |  |  | 
| Line 142  open_packet_socket (struct isis_circuit *circuit) | Line 144  open_packet_socket (struct isis_circuit *circuit) | 
 | * 8.4.2 - Broadcast subnetwork IIH PDUs | * 8.4.2 - Broadcast subnetwork IIH PDUs | 
 | * FIXME: is there a case only one will fail?? | * FIXME: is there a case only one will fail?? | 
 | */ | */ | 
| if (circuit->is_type & IS_LEVEL_1) | /* joining ALL_L1_ISS */ | 
| /* joining ALL_L1_ISS */ | retval |= isis_multicast_join (circuit->fd, 1, | 
| retval = isis_multicast_join (circuit->fd, 1, |  | 
 | circuit->interface->ifindex); | circuit->interface->ifindex); | 
| if (circuit->is_type & IS_LEVEL_2) | /* joining ALL_L2_ISS */ | 
| /* joining ALL_L2_ISS */ | retval |= isis_multicast_join (circuit->fd, 2, | 
| retval = isis_multicast_join (circuit->fd, 2, |  | 
 | circuit->interface->ifindex); | circuit->interface->ifindex); | 
 | /* joining ALL_ISS (used in RFC 5309 p2p-over-lan as well) */ | /* joining ALL_ISS (used in RFC 5309 p2p-over-lan as well) */ | 
| retval = isis_multicast_join (circuit->fd, 3, | retval |= isis_multicast_join (circuit->fd, 3, | 
 | circuit->interface->ifindex); | circuit->interface->ifindex); | 
 | } | } | 
 | else | else | 
| Line 231  isis_recv_pdu_bcast (struct isis_circuit *circuit, u_c | Line 231  isis_recv_pdu_bcast (struct isis_circuit *circuit, u_c | 
 | LLC_LEN, MSG_PEEK, | LLC_LEN, MSG_PEEK, | 
 | (struct sockaddr *) &s_addr, (socklen_t *) &addr_len); | (struct sockaddr *) &s_addr, (socklen_t *) &addr_len); | 
 |  |  | 
| if (bytesread < 0) | if ((bytesread < 0) || (s_addr.sll_ifindex != (int)circuit->interface->ifindex)) | 
 | { | { | 
| zlog_warn ("isis_recv_packet_bcast(): ifname %s, fd %d, bytesread %d, " | if (bytesread < 0) | 
| "recvfrom(): %s", | { | 
| circuit->interface->name, circuit->fd, bytesread, | zlog_warn ("isis_recv_packet_bcast(): ifname %s, fd %d, " | 
| safe_strerror (errno)); | "bytesread %d, recvfrom(): %s", | 
|  | circuit->interface->name, circuit->fd, bytesread, | 
|  | safe_strerror (errno)); | 
|  | } | 
|  | if (s_addr.sll_ifindex != (int)circuit->interface->ifindex) | 
|  | { | 
|  | zlog_warn("packet is received on multiple interfaces: " | 
|  | "socket interface %d, circuit interface %d, " | 
|  | "packet type %u", | 
|  | s_addr.sll_ifindex, circuit->interface->ifindex, | 
|  | s_addr.sll_pkttype); | 
|  | } | 
|  |  | 
 | /* get rid of the packet */ | /* get rid of the packet */ | 
 | bytesread = recvfrom (circuit->fd, discard_buff, sizeof (discard_buff), | bytesread = recvfrom (circuit->fd, discard_buff, sizeof (discard_buff), | 
 | MSG_DONTWAIT, (struct sockaddr *) &s_addr, | MSG_DONTWAIT, (struct sockaddr *) &s_addr, | 
| Line 324  isis_send_pdu_bcast (struct isis_circuit *circuit, int | Line 336  isis_send_pdu_bcast (struct isis_circuit *circuit, int | 
 | /* we need to do the LLC in here because of P2P circuits, which will | /* we need to do the LLC in here because of P2P circuits, which will | 
 | * not need it | * not need it | 
 | */ | */ | 
 | int written = 1; |  | 
 | struct sockaddr_ll sa; | struct sockaddr_ll sa; | 
 |  |  | 
 | stream_set_getp (circuit->snd_stream, 0); | stream_set_getp (circuit->snd_stream, 0); | 
| Line 357  isis_send_pdu_bcast (struct isis_circuit *circuit, int | Line 368  isis_send_pdu_bcast (struct isis_circuit *circuit, int | 
 | iov[1].iov_base = circuit->snd_stream->data; | iov[1].iov_base = circuit->snd_stream->data; | 
 | iov[1].iov_len = stream_get_endp (circuit->snd_stream); | iov[1].iov_len = stream_get_endp (circuit->snd_stream); | 
 |  |  | 
| written = sendmsg (circuit->fd, &msg, 0); | if (sendmsg(circuit->fd, &msg, 0) < 0) | 
|  | { | 
|  | zlog_warn("IS-IS pfpacket: could not transmit packet on %s: %s", | 
|  | circuit->interface->name, safe_strerror(errno)); | 
|  | if (ERRNO_IO_RETRY(errno)) | 
|  | return ISIS_WARNING; | 
|  | return ISIS_ERROR; | 
|  | } | 
 | return ISIS_OK; | return ISIS_OK; | 
 | } | } | 
 |  |  | 
 | int | int | 
 | isis_send_pdu_p2p (struct isis_circuit *circuit, int level) | isis_send_pdu_p2p (struct isis_circuit *circuit, int level) | 
 | { | { | 
 | int written = 1; |  | 
 | struct sockaddr_ll sa; | struct sockaddr_ll sa; | 
 |  | ssize_t rv; | 
 |  |  | 
 | stream_set_getp (circuit->snd_stream, 0); | stream_set_getp (circuit->snd_stream, 0); | 
 | memset (&sa, 0, sizeof (struct sockaddr_ll)); | memset (&sa, 0, sizeof (struct sockaddr_ll)); | 
| Line 382  isis_send_pdu_p2p (struct isis_circuit *circuit, int l | Line 399  isis_send_pdu_p2p (struct isis_circuit *circuit, int l | 
 |  |  | 
 | /* lets try correcting the protocol */ | /* lets try correcting the protocol */ | 
 | sa.sll_protocol = htons (0x00FE); | sa.sll_protocol = htons (0x00FE); | 
| written = sendto (circuit->fd, circuit->snd_stream->data, | rv = sendto(circuit->fd, circuit->snd_stream->data, | 
| stream_get_endp (circuit->snd_stream), 0, | stream_get_endp (circuit->snd_stream), 0, | 
| (struct sockaddr *) &sa, | (struct sockaddr *) &sa, | 
| sizeof (struct sockaddr_ll)); | sizeof (struct sockaddr_ll)); | 
|  | if (rv < 0) | 
|  | { | 
|  | zlog_warn("IS-IS pfpacket: could not transmit packet on %s: %s", | 
|  | circuit->interface->name, safe_strerror(errno)); | 
|  | if (ERRNO_IO_RETRY(errno)) | 
|  | return ISIS_WARNING; | 
|  | return ISIS_ERROR; | 
|  | } | 
 | return ISIS_OK; | return ISIS_OK; | 
 | } | } | 
 |  |  |