Home | History | Annotate | Download | only in netcan
History log of /src/sys/netcan/can.c
RevisionDateAuthorComments
 1.14  05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.13  04-Nov-2022  ozaki-r branches: 1.13.6; 1.13.8;
inpcb: rename functions to inpcb_*

Inspired by rmind-smpnet patches.
 1.12  03-Sep-2022  thorpej Convert CAN from a legacy netisr to pktqueue.
 1.11  31-Dec-2021  riastradh sys: Use if_ioctl wrapper function.
 1.10  21-Sep-2021  christos don't opencode kauth_cred_get()
 1.9  29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.8  19-Aug-2019  ozaki-r branches: 1.8.2;
can: add missing mowner variables for MBUFTRACE
 1.7  20-Jul-2019  bouyer Don't kmem_alloc()/kmem_free() with spin lock held: call can_pcbsetfilter()
without canp_mtx; take it here and check canp_state before updating the
canp_filters.
 1.6  15-Nov-2018  maxv Remove the 't' argument from m_tag_find().
 1.5  15-Nov-2018  maxv Simplify the mtag API:

- Remove m_tag_init(), m_tag_first(), m_tag_next() and
m_tag_delete_nonpersistent().

- Remove the 't' argument from m_tag_delete_chain().
 1.4  26-Jun-2018  msaitoh branches: 1.4.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.3  21-Mar-2018  roy Sprinkle more soroverflow().
 1.2  27-May-2017  bouyer branches: 1.2.2; 1.2.6; 1.2.10; 1.2.12;
merge the bouyer-socketcan branch to HEAD.

CAN stands for Controller Area Network, a broadcast network used
in automation and automotive fields. For example, the NMEA2000 standard
developped for marine devices uses a CAN network as the link layer.

This is an implementation of the linux socketcan API:
https://www.kernel.org/doc/Documentation/networking/can.txt
you can also see can(4).

This adds a new socket family (AF_CAN) and protocol (PF_CAN),
as well as the canconfig(8) utility, used to set timing parameter of
CAN hardware. Also inclued is a driver for the CAN controller
found in the allwinner A20 SoC (I tested it with an Olimex lime2 board,
connected with PIC18-based CAN devices).

There is also the canloop(4) pseudo-device, which allows to use
the socketcan API without CAN hardware.

At this time the CANFD part of the linux socketcan API is not implemented.
Error frames are not implemented either. But I could get the cansend and
canreceive utilities from the canutils package to build and run with minimal
changes. tcpudmp(8) can also be used to record frames, which can be
decoded with etherreal.
 1.1  15-Jan-2017  bouyer branches: 1.1.2;
file can.c was initially added on branch bouyer-socketcan.
 1.1.2.15  25-May-2017  bouyer Allow can_bpf_mtap() to call bpf_mtap_softint() when needed.
 1.1.2.14  22-May-2017  bouyer factor out if_attach() and bpf_attach() calls in can_ifattach().
Introduce can_ifdetach().
Introduce can_bpf_mtap(), which converts the can_id to network byte
order (as required by tcpdump/wireshark). Thanks to Guy Harris for
poiting this requirement.
 1.1.2.13  23-Apr-2017  bouyer Add locking and refcounting to canpcb.
Store the canpcb in the in the mbuf tag on send instead of the socket's address.
This should protect against a race where the socket cloud be closed before
we get back the mbuf from the adapter's driver.
 1.1.2.12  20-Apr-2017  bouyer If a packet was sent using sendto, the socket pointed to by the tag may
be unbound. Check for this in canintr().
XXX possibly the socket can completely dissapear before we get here.
This needs to be revisited.
 1.1.2.11  20-Apr-2017  bouyer Fix LINKMODE
Refuse to send packets if LISTENONLY is set
Don't forget to unbind in error case.
 1.1.2.10  19-Apr-2017  bouyer can_mbuf_tag_clean(): make sure we won't free the tag we will reuse.
Avoid mbuf leak in error paths.
 1.1.2.9  19-Apr-2017  bouyer Call if_alloc_sadl() for the interface, so that getifaddrs() will find
them.
 1.1.2.8  18-Apr-2017  bouyer Add can_ifinit_timings() helper function, which initialise timing parameters
to known invalid values.
 1.1.2.7  17-Apr-2017  bouyer Add infranstructure to configure timings from userland on a can interface.
This uses the SIOCGDRVSPEC/SIOCSDRVSPEC ioctls.
Compile-tested only.
 1.1.2.6  05-Feb-2017  bouyer more sanity checks on the mbuf we get.
 1.1.2.5  05-Feb-2017  bouyer Introduce can_ifattach(), for common setups of can interfaces.
Convert output to a ifq and change canloop_output to canloop_ifstart
 1.1.2.4  05-Feb-2017  bouyer Centralize mbuf tag cleanup, it will be used by real interface drivers too.
 1.1.2.3  05-Feb-2017  bouyer Implement CAN_RAW_FILTER socket option, and add tests for it.
 1.1.2.2  16-Jan-2017  bouyer Use PACKET_TAG_SO to store the sender's struct socket pointer, and use
it to implement socket options CAN_RAW_LOOPBACK and CAN_RAW_RECV_OWN_MSGS.
 1.1.2.1  15-Jan-2017  bouyer Initial commit of a CAN socket layer, compatible with linux SoccketCAN
(but incomplete). Based on work from Robert Swindells.
 1.2.12.3  26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.2.12.2  28-Jul-2018  pgoyette Sync with HEAD
 1.2.12.1  22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.2.10.2  03-Dec-2017  jdolecek update from HEAD
 1.2.10.1  27-May-2017  jdolecek file can.c was added on branch tls-maxphys on 2017-12-03 11:39:03 +0000
 1.2.6.2  28-Aug-2017  skrll Sync with HEAD
 1.2.6.1  27-May-2017  skrll file can.c was added on branch nick-nhusb on 2017-08-28 17:53:12 +0000
 1.2.2.1  09-Apr-2018  bouyer Pull up following revision(s) (requested by roy in ticket #724):
tests/net/icmp/t_ping.c: revision 1.19
sys/netinet6/raw_ip6.c: revision 1.166
sys/netinet6/ip6_input.c: revision 1.195
sys/net/raw_usrreq.c: revision 1.59
sys/sys/socketvar.h: revision 1.151
sys/kern/uipc_socket2.c: revision 1.128
tests/lib/libc/sys/t_recvmmsg.c: revision 1.2
lib/libc/sys/recv.2: revision 1.38
sys/net/rtsock.c: revision 1.239
sys/netinet/udp_usrreq.c: revision 1.246
sys/netinet6/icmp6.c: revision 1.224
tests/net/icmp/t_ping.c: revision 1.20
sys/netipsec/keysock.c: revision 1.63
sys/netinet/raw_ip.c: revision 1.172
sys/kern/uipc_socket.c: revision 1.260
tests/net/icmp/t_ping.c: revision 1.22
sys/kern/uipc_socket.c: revision 1.261
tests/net/icmp/t_ping.c: revision 1.23
sys/netinet/ip_mroute.c: revision 1.155
sbin/route/route.c: revision 1.159
sys/netinet6/ip6_mroute.c: revision 1.123
sys/netatalk/ddp_input.c: revision 1.31
sys/netcan/can.c: revision 1.3
sys/kern/uipc_usrreq.c: revision 1.184
sys/netinet6/udp6_usrreq.c: revision 1.138
tests/net/icmp/t_ping.c: revision 1.18
socket: report receive buffer overflows
Add soroverflow() which increments the overflow counter, sets so_error
to ENOBUFS and wakes the receive socket up.
Replace all code that manually increments this counter with soroverflow().
Add soroverflow() to raw_input().
This allows userland to detect route(4) overflows so it can re-sync
with the current state.
socket: clear error even when peeking
The error has already been reported and it's pointless requiring another
recv(2) call just to clear it.
socket: remove now incorrect comment that so_error is only udp
As it can be affected by route(4) sockets which are raw.
rtsock: log dropped messages that we cannot report to userland
Handle ENOBUFS when receiving messages.
Don't send messages if the receiver has died.
Sprinkle more soroverflow().
Handle ENOBUFS in recv
Handle ENOBUFS in sendto
Note value received. Harden another sendto for ENOBUFS.
Handle the routing socket overflowing gracefully.
Allow a valid sendto .... duh
Handle errors better.
Fix test for checking we sent all the data we asked to.
 1.4.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.4.2.1  10-Jun-2019  christos Sync with HEAD
 1.8.2.1  29-Feb-2020  ad Sync with head.
 1.13.8.1  02-Aug-2025  perseant Sync with HEAD
 1.13.6.1  15-Nov-2023  thorpej Rename ifq_enqueue() -> if_enqueue(), ifq_enqueue2() -> if_enqueue2().

RSS XML Feed