1: /*************************************************************************
2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
3: * by Michael Pounov <misho@elwix.org>
4: *
5: * $Author: misho $
6: * $Id: aitio.h,v 1.38.10.17 2013/12/15 22:31:44 misho Exp $
7: *
8: **************************************************************************
9: The ELWIX and AITNET software is distributed under the following
10: terms:
11:
12: All of the documentation and software included in the ELWIX and AITNET
13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
14:
15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
16: by Michael Pounov <misho@elwix.org>. All rights reserved.
17:
18: Redistribution and use in source and binary forms, with or without
19: modification, are permitted provided that the following conditions
20: are met:
21: 1. Redistributions of source code must retain the above copyright
22: notice, this list of conditions and the following disclaimer.
23: 2. Redistributions in binary form must reproduce the above copyright
24: notice, this list of conditions and the following disclaimer in the
25: documentation and/or other materials provided with the distribution.
26: 3. All advertising materials mentioning features or use of this software
27: must display the following acknowledgement:
28: This product includes software developed by Michael Pounov <misho@elwix.org>
29: ELWIX - Embedded LightWeight unIX and its contributors.
30: 4. Neither the name of AITNET nor the names of its contributors
31: may be used to endorse or promote products derived from this software
32: without specific prior written permission.
33:
34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44: SUCH DAMAGE.
45: */
46: #ifndef __AITIO_H
47: #define __AITIO_H
48:
49:
50: #define COMPAT_43TTY
51:
52: #include <assert.h>
53: #include <syslog.h>
54: #include <openssl/evp.h>
55: #include <openssl/aes.h>
56: #include <sys/tty.h>
57: #include <sys/ioctl_compat.h>
58: #include <sys/socket.h>
59: #include <sys/un.h>
60: #include <sys/uio.h>
61: #include <net/if_dl.h>
62: #include <net/bpf.h>
63: #include <netinet/in.h>
64: #include <elwix.h>
65: #include <aitsched.h>
66:
67:
68: #ifndef STRSIZ
69: #define STRSIZ 256
70: #endif
71:
72: #define IO_SOCK_ROLE_CLIENT 0
73: #define IO_SOCK_ROLE_SERVER 1
74:
75: #define IO_ETHER_FILTER_PROMISC 0
76: #define IO_ETHER_FILTER_NOTREAD -1
77: #define IO_ETHER_FILTER_READ 1
78: #define IO_ETHER_FILTER_WRITE 2
79:
80:
81: typedef struct {
82: unsigned int prog_inin; /* init progs */
83: unsigned int prog_maxn; /* max progs */
84: unsigned int prog_cnum; /* current progs */
85: unsigned int prog_poll; /* purge unused instances after sec */
86: char prog_name[PATH_MAX];
87:
88: pthread_mutex_t prog_mtx;
89: array_t *prog_fds;
90: unsigned int *prog_used;
91: } prog_t;
92:
93: typedef struct tagCliSock sock_cli_t;
94: typedef void *(*sock_cb_t)(sock_cli_t*);
95: struct tagCliSock {
96: void *cli_parent;
97: int cli_fd;
98: intptr_t cli_pty;
99: sockaddr_t cli_addr;
100: char cli_name[64];
101: char cli_cmdline[PATH_MAX];
102: pid_t cli_pid;
103:
104: sched_task_func_t cli_func;
105:
106: ait_val_t cli_buf[2];
107:
108: TAILQ_ENTRY(tagCliSock) cli_node;
109: };
110:
111: typedef struct {
112: int sock_role;
113: int sock_backq;
114: int sock_type;
115: int sock_proto;
116: int sock_fd;
117: struct timespec sock_timeout;
118: sockaddr_t sock_addr;
119: sockaddr_t sock_peer;
120:
121: ait_val_t sock_buf;
122: prog_t *sock_prog;
123:
124: volatile intptr_t sock_kill;
125: sched_root_task_t *sock_root;
126:
127: pthread_mutex_t sock_mtx;
128: TAILQ_HEAD(, tagCliSock) sock_cli;
129: } sock_t;
130:
131:
132: // io_GetErrno() Get error code of last operation
133: int io_GetErrno();
134: // io_GetError() Get error text of last operation
135: const char *io_GetError();
136:
137:
138: /*
139: * io_progInit() - Init program pool
140: *
141: * @progName = program name for execution
142: * @initNum = initial started programs
143: * @maxNum = maximum started programs
144: * return: NULL error or !=NULL allocated pool (must destroied with io_progDestroy())
145: */
146: prog_t *io_progInit(const char *progName,
147: unsigned int initNum, unsigned int maxNum);
148: /*
149: * io_progOpen() - Execute number of program(s)
150: *
151: * @prg = program pool
152: * @execNum = execute program(s) (0 max)
153: * return: -1 error, >0 executed programs
154: */
155: int io_progOpen(prog_t * __restrict prg, unsigned int execNum);
156: /*
157: * io_progOpen2() - Start program from pool on first unused slot
158: *
159: * @prg = program pool
160: * return: -1 error, >-1 reside at slot
161: */
162: int io_progOpen2(prog_t * __restrict prg);
163: /*
164: * io_progGrow() - Execute to number of programs in pool
165: *
166: * @prg = program pool
167: * @toNum = execute to number of programs (0 max)
168: * return: 0 error or nothing to do,
169: * >0 executed programs and abs(<0) executed programs with logged error
170: */
171: int io_progGrow(prog_t * __restrict prg, unsigned int toNum);
172: /*
173: * io_progVacuum() - Vacuum pool to running number of programs
174: *
175: * @prg = program pool
176: * @toNum = vacuum to number of programs (0 to init number)
177: * return: 0 error or >0 closed programs
178: */
179: int io_progVacuum(prog_t * __restrict prg, unsigned int toNum);
180: /*
181: * io_progCloseAt() - Close program at pool of certain position
182: *
183: * @prg = program pool
184: * @idx = index at pool
185: * return: 0 error or !=0 closed program
186: */
187: int io_progCloseAt(prog_t * __restrict prg, unsigned int idx);
188: /*
189: * io_progCloseOf() - Close program at pool with certain handle
190: *
191: * @prg = program pool
192: * @h = handle of program
193: * return: 0 error, >0 closed programs
194: */
195: #ifdef POPEN_STREAM
196: int io_progCloseOf(prog_t * __restrict prg, FILE *h);
197: #else
198: int io_progCloseOf(prog_t * __restrict prg, int h);
199: #endif
200: /*
201: * io_progClose() - Close all programs in pool
202: *
203: * @prg = program pool
204: * @closeNum = close program(s) (0 all)
205: * return: 0 error, >0 closed programs
206: */
207: int io_progClose(prog_t * __restrict prg, unsigned int closeNum);
208: /*
209: * io_progDestroy() - Destroy entire program pool
210: *
211: * @pprg = program pool
212: * return: none
213: */
214: void io_progDestroy(prog_t ** __restrict pprg);
215:
216: /*
217: * io_progCheck() - Check exit status of program pool
218: *
219: * @prg = program pool
220: * @re = resurrect program to init number
221: * return: -1 error or >-1 exited programs
222: */
223: int io_progCheck(prog_t * __restrict prg, int re);
224:
225: /*
226: * io_progAttach() - Attach to open program
227: *
228: * @prg = program pool
229: * @newOne = Execute new one program after attach
230: * return: NULL error or !=NULL attached program handle
231: */
232: #ifdef POPEN_STREAM
233: FILE *io_progAttach(prog_t * __restrict prg, int newOne);
234: #else
235: int io_progAttach(prog_t * __restrict prg, int newOne);
236: #endif
237: /*
238: * io_progDetach() - Detch from open program
239: *
240: * @prg= program pool
241: * @pfd = attached program handle
242: * return: none
243: */
244: #ifdef POPEN_STREAM
245: void io_progDetach(prog_t * __restrict prg, FILE *pfd);
246: #else
247: void io_progDetach(prog_t * __restrict prg, int pfd);
248: #endif
249:
250:
251: /*
252: * ioInitSocket() - Init socket and allocate resources
253: *
254: * @role = Socket role
255: * @type = Socket type
256: * @proto = Socket protocol
257: * @addr = Bind to address
258: * @port = Bind to port
259: * @buflen = Socket buffer, optional if =0 == BUFSIZ
260: * return: NULL error or !=NULL created socket
261: */
262: sock_t *ioInitSocket(int role, int type, int proto,
263: const char *addr, unsigned short port, size_t buflen);
264: /*
265: * ioCloseSocket() - Close socket and free resources
266: *
267: * @s = Socket
268: * return: none
269: */
270: void ioCloseSocket(sock_t ** __restrict s);
271: #define ioKillSocket(x) (assert((x)), (x)->sock_kill = 1)
272: /*
273: * ioCloseClient() - Close client socket
274: *
275: * @c = Client socket
276: * return: 0 ok or !=0 error
277: */
278: int ioCloseClient(sock_cli_t * __restrict c);
279: /*
280: * ioSetupProg2Socket() - Setup program pool to socket server
281: *
282: * @s = Socket
283: * @p = Program pool
284: * return: -1 error or 0 ok
285: */
286: int ioSetupProg2Socket(sock_t * __restrict s, prog_t * __restrict p);
287: /*
288: * ioUpSocket() - Setup socket for use
289: *
290: * @s = Socket
291: * @arg = Server role = listen backlog queue and Client role = peer address
292: * @timeout = Socket timeout in ms (default -1 infinit)
293: * return: -1 error or 0 ok
294: */
295: int ioUpSocket(sock_t * __restrict s, void *arg, int timeout);
296: /*
297: * ioUpdTimerSocket() - Update timeout of socket
298: *
299: * @c = Client socket
300: * return: none
301: */
302: void ioUpdTimerSocket(sock_cli_t * __restrict c);
303: /*
304: * ioLoopSocket() - Start socket scheduler
305: *
306: * @s = Socket
307: * @rcb = Read callback
308: * return: -1 error or return result from scheduler
309: */
310: int ioLoopSocket(sock_t * __restrict s, sched_task_func_t rcb);
311: /*
312: * ioBridgeProg2Socket() - Start socket scheduler and bridge program to socket
313: *
314: * @s = Socket
315: * @prgname = Program name
316: * return: 0 ok or !=0 error
317: */
318: int ioBridgeProg2Socket(sock_t * __restrict s, const char *prgname);
319:
320:
321: /*
322: * ioPromptRead() - Read data from input h[0] with prompt to output h[1]
323: *
324: * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
325: * @csPrompt = Prompt before input, may be NULL
326: * @psData = Readed data
327: * @dataLen = Length of data
328: * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
329: */
330: int ioPromptRead(int *h, const char *csPrompt,
331: char * __restrict psData, int dataLen);
332: /*
333: * ioPromptPassword() - Read password from input h[0] with prompt to output h[1]
334: *
335: * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
336: * @csPrompt = Prompt before input, may be NULL
337: * @psPass = Readed password
338: * @passLen = Length of password
339: * @confirm = Confirm password, 0 - get password, !=0 Ask for confirmation
340: * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
341: */
342: int ioPromptPassword(int *h, const char *csPrompt,
343: char * __restrict psPass, int passLen, int confirm);
344:
345:
346: /*
347: * ioMkDir() - Function for racursive directory creation and validation
348: *
349: * @csDir = Full directory path
350: * @mode = Mode for directory creation if missing dir
351: * return: -1 error, 0 directory path exist, >0 created missing dirs
352: */
353: int ioMkDir(const char *csDir, int mode);
354:
355: /*
356: * ioWatchDirLoop() - Function for watching changes in directory and fire callback
357: *
358: * @csDir = Full directory path
359: * @callback = Callback if raise event! nOp -1 delete, 0 change/move, 1 create
360: * return: -1 error, !=-1 ok, number of total signaled events
361: */
362: int ioWatchDirLoop(const char *csDir, int (*callback)(const char *csName, int nOp));
363:
364:
365: #ifdef AIO_OPS
366: /*
367: * io_aiobulk() - AIO bulk R/W function
368: *
369: * @mode = Bulk wait mode
370: * @acbs = List of aiocb structures
371: * @nacb = Number of aiocb in list
372: * @sig = Event for completed operations, may be =NULL
373: * return: -1 error or 0 ok
374: */
375: int io_aiobulk(int mode, struct aiocb ** __restrict acbs, int nacb,
376: struct sigevent *sig);
377: #endif
378: /*
379: * io_rreadv() - Raw VFS bulk read function
380: *
381: * @fd = File handle
382: * @bufs = Read buffers
383: * @nbufs = Number of read buffers
384: * @offset = Read from position, if -1 read nbytes from current position
385: * @update = Update file handle position !0
386: * return: -1 error or !=-1 readed bytes
387: */
388: int io_rreadv(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset,
389: int update);
390: /*
391: * io_rwritev() - Raw VFS bulk write function
392: *
393: * @fd = File handle
394: * @bufs = Write buffers
395: * @nbufs = Number of write buffers
396: * @offset = Write to position, if -1 write nbytes to current position
397: * @update = Update file handle position !0
398: * return: -1 error or !=-1 written bytes
399: */
400: int io_rwritev(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset,
401: int update);
402: /*
403: * io_rread() - Raw VFS read function
404: *
405: * @fd = File handle
406: * @buf = Read buffer
407: * @nbytes = Read buffer size
408: * @offset = Read from position, if -1 read nbytes from current position
409: * @update = Update file handle position !0
410: * return: -1 error or !=-1 readed bytes
411: */
412: int io_rread(int fd, void * __restrict buf, size_t nbytes, off_t offset,
413: int update);
414: /*
415: * io_rwrite() - Raw VFS write function
416: *
417: * @fd = File handle
418: * @buf = Write buffer
419: * @nbytes = Write bytes from buffer
420: * @offset = Write at position, if -1 write nbytes from current position
421: * @update = Update file handle position !0
422: * return: -1 error or !=-1 written bytes
423: */
424: int io_rwrite(int fd, void * __restrict buf, size_t nbytes, off_t offset,
425: int update);
426:
427: /* Disk I/O helper macros */
428: #define io_read(f, b, n) io_rread(f, b, n, -1, 1)
429: #define io_write(f, b, n) io_rwrite(f, b, n, -1, 1)
430:
431:
432: /* Crypto framework */
433:
434: /*
435: * ioCipher() - Cipher wrapper for all supported crypto algorythms
436: *
437: * @pInput = input buffer
438: * @inLen = input buffer len
439: * @ppOutput = output allocated buffe, must be e_free after use
440: * @Cipher = cipher engine, like EVP_bf_cbc() or etc...
441: * @pKey = key
442: * @pIV = IV, salt (8 bytes)
443: * @nMode = Mode 0 - decrypting or 1 - encrypting
444: * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
445: */
446: int ioCipher(unsigned char *pInput, int inLen, unsigned char **ppOutput, const EVP_CIPHER *Cipher,
447: unsigned char *pKey, unsigned char *pIV, int nMode);
448:
449: /*
450: * io_Blowfish() - Blowfish cipher algorythm, work with ASCII hex strings
451: *
452: * @pInput = input buffer
453: * @inLen = input buffer len
454: * @ppOutput = output allocated buffe, must be e_free after use
455: * @pKey = key
456: * @pIV = IV, salt (8 bytes)
457: * @nMode = Mode 0 - decrypting or 1 - encrypting
458: * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
459: */
460: int io_Blowfish(unsigned char *pInput, int inLen, unsigned char **ppOutput,
461: unsigned char *pKey, unsigned char *pIV, int nMode);
462: /*
463: * io_ctr_AES() - Encrypt/Decrypt stream cipher CTR_AES
464: *
465: * @pInput = Input buffer with ASCII
466: * @inLen = Input buffer data length
467: * @ppOutput = Output buffer with cipher data, must be e_free after use
468: * @pKey = Key
469: * @IV = IVector/Nonce/Counter, Warning: IV must be variable, because we write there!!!
470: * return: -1 error or >-1 how many cipher blocks proceeded
471: */
472: int io_ctr_AES(unsigned char *pInput, int inLen, unsigned char **ppOutput,
473: unsigned char *pKey, unsigned char IV[AES_BLOCK_SIZE]);
474:
475:
476: /*
477: * ioAllocPTY() - Allocate new PTY and TTY
478: *
479: * @ptyfd = master fd, pty
480: * @ttyfd = slave fd, tty
481: * @name = tty device name if not null
482: * @namesiz = name length, must be above 63 bytes.
483: * @term = termios for terminal
484: * @winz = winsize for terminal
485: * return: -1 error or 0 ok
486: */
487: int ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict name, int namesiz,
488: struct termios * __restrict term, struct winsize * __restrict winz);
489: /*
490: * ioFreePTY() - Release PTY and TTY device
491: *
492: * @ptyfd = master fd, pty (==-1 skip closing pty)
493: * @ttyname = tty filename
494: * return: none
495: */
496: void ioFreePTY(int ptyfd, const char *ttyname);
497: /*
498: * ioChgWinPTY() - Change window size of PTY
499: *
500: * @ptyfd = master fd, pty
501: * @row = row
502: * @col = col
503: * @xpxl = x pixels
504: * @ypxl = y pixels
505: * return: -1 error or 0 ok
506: */
507: int ioChgWinPTY(int ptyfd, unsigned short row, unsigned short col,
508: unsigned short xpxl, unsigned short ypxl);
509: /*
510: * ioSetOwnerTTY() - Set owner to TTY
511: *
512: * @ttyname = tty filename
513: * @UID = uid
514: * @GID = gid
515: * return: -1 error or 0 ok
516: */
517: int ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GID);
518: /*
519: * ioSetSidTTY() - Makes the process's controlling TTY and sets it to sane modes.
520: *
521: * @ttyfd = slave fd, tty
522: * @ttyname = tty filename
523: * return: -1 error or 0 ok
524: */
525: int ioSetSidTTY(int *ttyfd, const char *ttyname);
526: /*
527: * ioSetRAWMode() - Enter into RAW mode
528: *
529: * @fd = tty fd
530: * @otio = saved old termios for later restore if !=NULL
531: * return: -1 error or 0 ok
532: */
533: int ioSetRAWMode(int fd, struct termios *otio);
534: /*
535: * ioRestoreMode() - Restore termios to tty fd
536: *
537: * @fd = tty fd
538: * @tio = termios structure for restore
539: * return: -1 error or 0 ok
540: */
541: int ioRestoreMode(int fd, struct termios tio);
542: /*
543: * ioForkPTY() - Fork new process with session leader and new TTY
544: *
545: * @ptyfd = master fd, pty
546: * @name = tty device name if not null
547: * @namesiz = name length, must be above 63 bytes.
548: * @term = termios for terminal
549: * @winz = winsize for terminal
550: * @otio = old termios structure for restore
551: * return: -1 error, 0 child process or >0 parent: pid of child
552: */
553: pid_t ioForkPTY(int *ptyfd, char * __restrict name, int namesiz, struct termios * __restrict term,
554: struct winsize * __restrict winz, struct termios * __restrict otio);
555:
556: /*
557: * ioCreatePIDFile() - Create PID file
558: *
559: * @csName = PID filename
560: * @ifExists = !=0 if filename exists return error
561: * return: -1 error or 0 ok
562: */
563: int ioCreatePIDFile(const char *csName, int ifExists);
564:
565: /*
566: * ioSendFile() - AITNET sendfile() userland implementation, not dependant from OS
567: *
568: * @s = socket
569: * @csFile = file for send
570: * @sendLen = bytes to send, if 0 send all data
571: * @offset = start file offset
572: * @sndbuf = SO_SNDBUF value, if 0 use default
573: * return: 0 error, >0 ok, sended bytes
574: */
575: size_t ioSendFile(int s, const char *csFile, size_t sendLen, off_t offset, int sndbuf);
576: /*
577: * ioRecvFile() - Receive file from socket, fastest (zero-copy) way
578: *
579: * @s = socket
580: * @csFile = file for receive
581: * @recvLen = receive bytes
582: * @over = overwrite file if exists with mode like 0644
583: * @rcvbuf = SO_RCVBUF value, if 0 use default
584: * return: 0 error, >0 ok, received bytes
585: */
586: size_t ioRecvFile(int s, const char *csFile, size_t recvLen, int over, int rcvbuf);
587:
588: /*
589: * ioRealFileName() - Get real file name
590: *
591: * @fname = filename
592: * return: =NULL error or !=NULL real filename, should be free with e_free()
593: */
594: char *ioRealFileName(const char *fname);
595:
596: /* Buffered file access over memory block */
597:
598: /*
599: * io_fmemopen() - File buffered stream operations over memory block
600: *
601: * @base = Base address of memory block, if =NULL Infinit length(auto-grow)
602: * @basesize = Size of memory block
603: * return: NULL error or !=NULL Opened file resource
604: */
605: FILE *io_fmemopen(void ** __restrict base, off_t basesize);
606: /*
607: * io_fmapopen() - File buffered stream operations over MMAP block
608: *
609: * @csFile = Filename for MMAP, if =NULL private MMAP block
610: * @mode = File open mode
611: * @perm = If file not exists will be created with this access permissions
612: * @prot = MMAP protection
613: * @flags = MMAP mode flags
614: * @offset = Map from file offset, if csFile==NULL then this is size of MMAP private block
615: * return: NULL error or !=NULL Opened file resource
616: */
617: FILE *io_fmapopen(const char *csFile, int mode, int perm, int prot, int flags, off_t offset);
618: /*
619: * io_fd2buf() - Convert open file handle to buffered file I/O
620: *
621: * @fd = File handle
622: * @mode = Permissions for new buffered file I/O
623: * return: NULL error or open buffered file
624: */
625: FILE *io_fd2buf(int fd, const char *mode);
626: /*
627: * io_dumbFile() - Create empry or dumb file with fixed size
628: *
629: * @csFile = Filename for create
630: * @mode = File access permissions
631: * @size = File size
632: * return: -1 error or open file handle
633: */
634: int io_dumbFile(const char *csFile, int mode, off_t size);
635:
636:
637: /*
638: * io_get1stiface() - Get first interface of host
639: *
640: * @szIface = interface string buffer
641: * @iflen = size of interface buffer
642: * return: -1 error or 0 ok
643: */
644: int io_get1stiface(char *szIface, int iflen);
645: /*
646: * io_getmaciface() - Get MAC address from interface name
647: *
648: * @csIface = interface name
649: * @ea = ethernet address
650: * return: -1 error, 0 ok or 1 not found
651: */
652: int io_getmaciface(const char *csIface, ether_addr_t * __restrict ea);
653: /*
654: * io_etherOpen() - Open BPF interface to device
655: *
656: * @csIface = interface name
657: * @flags = open flags
658: * @whdr = with complete headers
659: * @wdlt = with data link type
660: * @buflen = buffer length
661: * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
662: * return: -1 error or >-1 bpf handle
663: */
664: int io_etherOpen(const char *csIface, int flags, int whdr, int wdlt,
665: unsigned int *buflen, void **zcbuf);
666: /*
667: * io_etherClose() - Close BPF interface
668: *
669: * @eth = bpf handle
670: * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
671: * return: none
672: */
673: void io_etherClose(int eth, void **zcbuf);
674:
675: /*
676: * io_etherFilter() - BPF filter routine
677: *
678: * @eth = bpf handle
679: * @io = filter direction
680: * (IO_ETHER_FILTER_PROMISC|IO_ETHER_FILTER_NOTREAD|IO_ETHER_FILTER_READ|IO_ETHER_FILTER_WRITE)
681: * @insn = BPF filter instruction array
682: * @insnlen = Length of BPF filter instruction array
683: * return: -1 error or 0 ok
684: */
685: int io_etherFilter(int eth, int io, struct bpf_insn * __restrict insn, size_t insnlen);
686:
687: /*
688: * io_etherSend() - Send packet to bpf
689: *
690: * @eth = bpf handle
691: * @buf = buffer
692: * @buflen = buffer length
693: * return: -1 error or !=-1 written bytes
694: */
695: ssize_t io_etherSend(int eth, const void *buf, size_t buflen);
696: /*
697: * io_etherRecv() - Receive packet from bpf
698: *
699: * @eth = bpf handle
700: * @buf = buffer
701: * @buflen = buffer length
702: * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
703: * return: -1 error or !=-1 readed bytes
704: */
705: ssize_t io_etherRecv(int eth, void * __restrict buf,
706: size_t buflen, void * __restrict zcbuf);
707:
708:
709: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>