net_io.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1991,1990,1989 Carnegie Mellon University
  4. * All Rights Reserved.
  5. *
  6. * Permission to use, copy, modify and distribute this software and its
  7. * documentation is hereby granted, provided that both the copyright
  8. * notice and this permission notice appear in all copies of the
  9. * software, derivative works or modified versions, and any portions
  10. * thereof, and that both notices appear in supporting documentation.
  11. *
  12. * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13. * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14. * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15. *
  16. * Carnegie Mellon requests users of this software to return to
  17. *
  18. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  19. * School of Computer Science
  20. * Carnegie Mellon University
  21. * Pittsburgh PA 15213-3890
  22. *
  23. * any improvements or extensions that they make and grant Carnegie Mellon
  24. * the rights to redistribute these changes.
  25. */
  26. /*
  27. * Author: David B. Golub, Carnegie Mellon University
  28. * Date: ll/89
  29. */
  30. #ifndef _DEVICE_NET_IO_H_
  31. #define _DEVICE_NET_IO_H_
  32. /*
  33. * Utilities for playing with network messages.
  34. */
  35. #include <mach/machine/vm_types.h>
  36. #include <ipc/ipc_kmsg.h>
  37. #include <kern/macros.h>
  38. #include <kern/lock.h>
  39. #include <kern/kalloc.h>
  40. #include <device/if_hdr.h>
  41. #include <device/io_req.h>
  42. #include <device/net_status.h>
  43. struct net_rcv_port;
  44. typedef struct net_rcv_port *net_rcv_port_t;
  45. struct net_hash_entry;
  46. typedef struct net_hash_entry *net_hash_entry_t;
  47. struct net_hash_header;
  48. typedef struct net_hash_header *net_hash_header_t;
  49. /*
  50. * A network packet is wrapped in a kernel message while in
  51. * the kernel.
  52. */
  53. #define net_kmsg(kmsg) ((net_rcv_msg_t)&(kmsg)->ikm_header)
  54. /*
  55. * Interrupt routines may allocate and free net_kmsgs with these
  56. * functions. net_kmsg_get may return IKM_NULL.
  57. */
  58. extern ipc_kmsg_t net_kmsg_get(void);
  59. extern void net_kmsg_put(ipc_kmsg_t);
  60. /*
  61. * Network utility routines.
  62. */
  63. extern void net_ast(void);
  64. extern void net_packet(struct ifnet *, ipc_kmsg_t, unsigned int, boolean_t);
  65. extern void net_filter(ipc_kmsg_t, ipc_kmsg_queue_t);
  66. extern io_return_t net_getstat(struct ifnet *, dev_flavor_t, dev_status_t,
  67. natural_t *);
  68. extern io_return_t net_write(struct ifnet *, int (*)(), io_req_t);
  69. /*
  70. * Non-interrupt code may allocate and free net_kmsgs with these functions.
  71. */
  72. extern vm_size_t net_kmsg_size;
  73. extern void net_kmsg_collect (void);
  74. extern void net_io_init(void);
  75. extern void net_thread(void) __attribute__ ((noreturn));
  76. #define net_kmsg_alloc() ((ipc_kmsg_t) kalloc(net_kmsg_size))
  77. #define net_kmsg_free(kmsg) kfree((vm_offset_t) (kmsg), net_kmsg_size)
  78. extern unsigned int ntohl(unsigned int);
  79. extern unsigned short int ntohs(unsigned short int);
  80. extern unsigned int htonl(unsigned int);
  81. extern unsigned short int htons(unsigned short int);
  82. unsigned int bpf_hash(int n, const unsigned int *keys);
  83. extern boolean_t
  84. net_do_filter(
  85. net_rcv_port_t infp,
  86. const char * data,
  87. unsigned int data_count,
  88. const char * header); /* CSPF */
  89. extern int
  90. bpf_do_filter(
  91. net_rcv_port_t infp,
  92. char * p,
  93. unsigned int wirelen,
  94. char * header,
  95. unsigned int hlen,
  96. net_hash_entry_t **hash_headpp,
  97. net_hash_entry_t *entpp); /* BPF */
  98. int hash_ent_remove(
  99. struct ifnet *ifp,
  100. net_hash_header_t hp,
  101. int used,
  102. net_hash_entry_t *head,
  103. net_hash_entry_t entp,
  104. queue_entry_t *dead_p);
  105. void net_free_dead_infp(queue_entry_t dead_infp);
  106. void net_free_dead_entp (queue_entry_t dead_entp);
  107. int bpf_validate(
  108. bpf_insn_t f,
  109. int bytes,
  110. bpf_insn_t *match);
  111. int bpf_eq(
  112. bpf_insn_t f1,
  113. bpf_insn_t f2,
  114. int bytes);
  115. int net_add_q_info(ipc_port_t rcv_port);
  116. int bpf_match (
  117. net_hash_header_t hash,
  118. int n_keys,
  119. const unsigned int *keys,
  120. net_hash_entry_t **hash_headpp,
  121. net_hash_entry_t *entpp);
  122. #endif /* _DEVICE_NET_IO_H_ */