netdrv.h 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. netdrv.h
  9. Abstract:
  10. This header contains definitions necessary for implementing network
  11. drivers.
  12. Author:
  13. Evan Green 4-Apr-2013
  14. --*/
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. #include <minoca/devinfo/net.h>
  19. //
  20. // --------------------------------------------------------------------- Macros
  21. //
  22. //
  23. // Define macros to convert from CPU to network format and back.
  24. //
  25. #define CPU_TO_NETWORK64(_Input) RtlByteSwapUlonglong(_Input)
  26. #define NETWORK_TO_CPU64(_Input) RtlByteSwapUlonglong(_Input)
  27. #define CPU_TO_NETWORK32(_Input) RtlByteSwapUlong(_Input)
  28. #define NETWORK_TO_CPU32(_Input) RtlByteSwapUlong(_Input)
  29. #define CPU_TO_NETWORK16(_Input) RtlByteSwapUshort(_Input)
  30. #define NETWORK_TO_CPU16(_Input) RtlByteSwapUshort(_Input)
  31. //
  32. // This macro gets a network sockets last error.
  33. //
  34. #define NET_SOCKET_GET_LAST_ERROR(_Socket) (_Socket)->LastError
  35. //
  36. // This macro gets and clears a network sockets last error.
  37. //
  38. #define NET_SOCKET_GET_AND_CLEAR_LAST_ERROR(_Socket) \
  39. RtlAtomicExchange32((volatile ULONG *)&((_Socket)->LastError), \
  40. STATUS_SUCCESS);
  41. //
  42. // This macro sets the network sockets last error state.
  43. //
  44. #define NET_SOCKET_SET_LAST_ERROR(_Socket, _Error) \
  45. RtlAtomicExchange32((volatile ULONG *)&((_Socket)->LastError), (_Error));
  46. //
  47. // This macro clears the network sockets last error state.
  48. //
  49. #define NET_SOCKET_CLEAR_LAST_ERROR(_Socket) \
  50. NET_SOCKET_GET_AND_CLEAR_LAST_ERROR(_Socket)
  51. //
  52. // This macro initializes a network packet list.
  53. //
  54. #define NET_INITIALIZE_PACKET_LIST(_PacketList) \
  55. INITIALIZE_LIST_HEAD(&((_PacketList)->Head)); \
  56. (_PacketList)->Count = 0;
  57. //
  58. // This macro adds a network packet to a network packet list.
  59. //
  60. #define NET_ADD_PACKET_TO_LIST(_Packet, _PacketList) \
  61. INSERT_BEFORE(&((_Packet)->ListEntry), &((_PacketList)->Head)); \
  62. (_PacketList)->Count += 1;
  63. //
  64. // This macro adds a network packet to beginning of a network packet list.
  65. //
  66. #define NET_ADD_PACKET_TO_LIST_HEAD(_Packet, _PacketList) \
  67. INSERT_AFTER(&((_Packet)->ListEntry), &((_PacketList)->Head)); \
  68. (_PacketList)->Count += 1;
  69. //
  70. // This macro removes a network packet from a network packet list.
  71. //
  72. #define NET_REMOVE_PACKET_FROM_LIST(_Packet, _PacketList) \
  73. LIST_REMOVE(&(_Packet)->ListEntry); \
  74. (_PacketList)->Count -= 1;
  75. //
  76. // This macro inserts a new packet before an existing packet.
  77. //
  78. #define NET_INSERT_PACKET_BEFORE(_New, _Existing, _PacketList) \
  79. INSERT_BEFORE(&((_New)->ListEntry), &((_Existing)->ListEntry)); \
  80. (_PacketList)->Count += 1;
  81. //
  82. // This macro inserts a new packet after an existing packet.
  83. //
  84. #define NET_INSERT_PACKET_AFTER(_New, _Existing, _PacketList) \
  85. INSERT_AFTER(&((_New)->ListEntry), &((_Existing)->ListEntry)); \
  86. (_PacketList)->Count += 1;
  87. //
  88. // This macro determines if the packet list is empty.
  89. //
  90. #define NET_PACKET_LIST_EMPTY(_PacketList) ((_PacketList)->Count == 0)
  91. //
  92. // This macro appends a list of network packets to another list of network
  93. // packets, leaving the original appended list empty.
  94. //
  95. #define NET_APPEND_PACKET_LIST(_AppendList, _ExistingList) \
  96. APPEND_LIST(&((_AppendList)->Head), &((_ExistingList)->Head)); \
  97. (_ExistingList)->Count += (_AppendList)->Count; \
  98. NET_INITIALIZE_PACKET_LIST(_AppendList);
  99. //
  100. // ---------------------------------------------------------------- Definitions
  101. //
  102. #ifndef NET_API
  103. #define NET_API __DLLIMPORT
  104. #endif
  105. //
  106. // Define the current version number of the net link properties structure.
  107. //
  108. #define NET_LINK_PROPERTIES_VERSION 1
  109. //
  110. // Define some common network link speeds.
  111. //
  112. #define NET_SPEED_NONE 0
  113. #define NET_SPEED_10_MBPS 10000000ULL
  114. #define NET_SPEED_100_MBPS 100000000ULL
  115. #define NET_SPEED_1000_MBPS 1000000000ULL
  116. #define NET_SPEED_2500_MBPS 2500000000ULL
  117. //
  118. // Define well-known protocol numbers.
  119. //
  120. #define IP4_PROTOCOL_NUMBER 0x0800
  121. #define IP6_PROTOCOL_NUMBER 0x86DD
  122. #define ARP_PROTOCOL_NUMBER 0x0806
  123. #define EAPOL_PROTOCOL_NUMBER 0x888E
  124. //
  125. // Define an "invalid" protocol number for networks that don't actually expect
  126. // to receive packets from the physical layer (e.g. Netlink).
  127. //
  128. #define INVALID_PROTOCOL_NUMBER (ULONG)-1
  129. //
  130. // Define the network socket flags.
  131. //
  132. #define NET_SOCKET_FLAG_REUSE_ANY_ADDRESS 0x00000001
  133. #define NET_SOCKET_FLAG_REUSE_TIME_WAIT 0x00000002
  134. #define NET_SOCKET_FLAG_REUSE_EXACT_ADDRESS 0x00000004
  135. #define NET_SOCKET_FLAG_BROADCAST_ENABLED 0x00000008
  136. #define NET_SOCKET_FLAG_ACTIVE 0x00000010
  137. #define NET_SOCKET_FLAG_PREVIOUSLY_ACTIVE 0x00000020
  138. #define NET_SOCKET_FLAG_TIME_WAIT 0x00000040
  139. #define NET_SOCKET_FLAG_FORKED_LISTENER 0x00000080
  140. #define NET_SOCKET_FLAG_NETWORK_HEADER_INCLUDED 0x00000100
  141. #define NET_SOCKET_FLAG_KERNEL 0x00000200
  142. #define NET_SOCKET_FLAG_MULTICAST_LOOPBACK 0x00000400
  143. //
  144. // Define the set of network socket flags that should be carried over to a
  145. // copied socket after a spawned connection.
  146. //
  147. #define NET_SOCKET_FLAGS_INHERIT_MASK 0x0000040F
  148. //
  149. // Define the network buffer allocation flags.
  150. //
  151. #define NET_ALLOCATE_BUFFER_FLAG_ADD_DEVICE_LINK_HEADERS 0x00000001
  152. #define NET_ALLOCATE_BUFFER_FLAG_ADD_DEVICE_LINK_FOOTERS 0x00000002
  153. #define NET_ALLOCATE_BUFFER_FLAG_ADD_DATA_LINK_HEADERS 0x00000004
  154. #define NET_ALLOCATE_BUFFER_FLAG_ADD_DATA_LINK_FOOTERS 0x00000008
  155. #define NET_ALLOCATE_BUFFER_FLAG_UNENCRYPTED 0x00000010
  156. //
  157. // Define the network packet flags.
  158. //
  159. #define NET_PACKET_FLAG_IP_CHECKSUM_OFFLOAD 0x00000001
  160. #define NET_PACKET_FLAG_UDP_CHECKSUM_OFFLOAD 0x00000002
  161. #define NET_PACKET_FLAG_TCP_CHECKSUM_OFFLOAD 0x00000004
  162. #define NET_PACKET_FLAG_IP_CHECKSUM_FAILED 0x00000008
  163. #define NET_PACKET_FLAG_UDP_CHECKSUM_FAILED 0x00000010
  164. #define NET_PACKET_FLAG_TCP_CHECKSUM_FAILED 0x00000020
  165. #define NET_PACKET_FLAG_FORCE_TRANSMIT 0x00000040
  166. #define NET_PACKET_FLAG_UNENCRYPTED 0x00000080
  167. #define NET_PACKET_FLAG_MULTICAST 0x00000100
  168. #define NET_PACKET_FLAG_ROUTER_ALERT 0x00000200
  169. #define NET_PACKET_FLAG_LINK_LOCAL_HOP_LIMIT 0x00000400
  170. #define NET_PACKET_FLAG_MAX_HOP_LIMIT 0x00000800
  171. #define NET_PACKET_FLAG_CHECKSUM_OFFLOAD_MASK \
  172. (NET_PACKET_FLAG_IP_CHECKSUM_OFFLOAD | \
  173. NET_PACKET_FLAG_UDP_CHECKSUM_OFFLOAD | \
  174. NET_PACKET_FLAG_TCP_CHECKSUM_OFFLOAD)
  175. //
  176. // Define the network link capabilities.
  177. //
  178. #define NET_LINK_CAPABILITY_TRANSMIT_IP_CHECKSUM_OFFLOAD 0x00000001
  179. #define NET_LINK_CAPABILITY_TRANSMIT_UDP_CHECKSUM_OFFLOAD 0x00000002
  180. #define NET_LINK_CAPABILITY_TRANSMIT_TCP_CHECKSUM_OFFLOAD 0x00000004
  181. #define NET_LINK_CAPABILITY_RECEIVE_IP_CHECKSUM_OFFLOAD 0x00000008
  182. #define NET_LINK_CAPABILITY_RECEIVE_UDP_CHECKSUM_OFFLOAD 0x00000010
  183. #define NET_LINK_CAPABILITY_RECEIVE_TCP_CHECKSUM_OFFLOAD 0x00000020
  184. #define NET_LINK_CAPABILITY_PROMISCUOUS_MODE 0x00000040
  185. #define NET_LINK_CAPABILITY_MULTICAST_ALL 0x00000080
  186. #define NET_LINK_CAPABILITY_CHECKSUM_TRANSMIT_MASK \
  187. (NET_LINK_CAPABILITY_TRANSMIT_IP_CHECKSUM_OFFLOAD | \
  188. NET_LINK_CAPABILITY_TRANSMIT_UDP_CHECKSUM_OFFLOAD | \
  189. NET_LINK_CAPABILITY_TRANSMIT_TCP_CHECKSUM_OFFLOAD)
  190. #define NET_LINK_CAPABILITY_CHECKSUM_RECEIVE_MASK \
  191. (NET_LINK_CAPABILITY_RECEIVE_IP_CHECKSUM_OFFLOAD | \
  192. NET_LINK_CAPABILITY_RECEIVE_UDP_CHECKSUM_OFFLOAD | \
  193. NET_LINK_CAPABILITY_RECEIVE_TCP_CHECKSUM_OFFLOAD)
  194. #define NET_LINK_CAPABILITY_CHECKSUM_MASK \
  195. (NET_LINK_CAPABILITY_CHECKSUM_TRANSMIT_MASK | \
  196. NET_LINK_CAPABILITY_CHECKSUM_RECEIVE_MASK)
  197. //
  198. // Define the network packet size information flags.
  199. //
  200. #define NET_PACKET_SIZE_FLAG_UNENCRYPTED 0x00000001
  201. //
  202. // Define the socket binding flags.
  203. //
  204. #define NET_SOCKET_BINDING_FLAG_ACTIVATE 0x00000001
  205. #define NET_SOCKET_BINDING_FLAG_NO_PORT_ASSIGNMENT 0x00000002
  206. #define NET_SOCKET_BINDING_FLAG_ALLOW_REBIND 0x00000004
  207. #define NET_SOCKET_BINDING_FLAG_ALLOW_UNBIND 0x00000008
  208. #define NET_SOCKET_BINDING_FLAG_OVERWRITE_LOCAL 0x00000010
  209. #define NET_SOCKET_BINDING_FLAG_SKIP_ADDRESS_VALIDATION 0x00000020
  210. //
  211. // Define the protocol entry flags.
  212. //
  213. #define NET_PROTOCOL_FLAG_UNICAST_ONLY 0x00000001
  214. #define NET_PROTOCOL_FLAG_MATCH_ANY_PROTOCOL 0x00000002
  215. #define NET_PROTOCOL_FLAG_FIND_ALL_SOCKETS 0x00000004
  216. #define NET_PROTOCOL_FLAG_NO_DEFAULT_PROTOCOL 0x00000008
  217. #define NET_PROTOCOL_FLAG_PORTLESS 0x00000010
  218. #define NET_PROTOCOL_FLAG_NO_BIND_PERMISSIONS 0x00000020
  219. #define NET_PROTOCOL_FLAG_CONNECTION_BASED 0x00000040
  220. //
  221. // ------------------------------------------------------ Data Type Definitions
  222. //
  223. typedef enum _NET_SOCKET_BINDING_TYPE {
  224. SocketUnbound,
  225. SocketLocallyBound,
  226. SocketFullyBound,
  227. SocketBindingTypeCount,
  228. SocketBindingInvalid
  229. } NET_SOCKET_BINDING_TYPE, *PNET_SOCKET_BINDING_TYPE;
  230. typedef enum _NET_LINK_INFORMATION_TYPE {
  231. NetLinkInformationInvalid,
  232. NetLinkInformationChecksumOffload,
  233. NetLinkInformationPromiscuousMode,
  234. NetLinkInformationMulticastAll,
  235. } NET_LINK_INFORMATION_TYPE, *PNET_LINK_INFORMATION_TYPE;
  236. typedef enum _NET_ADDRESS_TYPE {
  237. NetAddressUnknown,
  238. NetAddressAny,
  239. NetAddressUnicast,
  240. NetAddressBroadcast,
  241. NetAddressMulticast
  242. } NET_ADDRESS_TYPE, *PNET_ADDRESS_TYPE;
  243. typedef enum _NET_LINK_ADDRESS_STATE {
  244. NetLinkAddressNotConfigured,
  245. NetLinkAddressTentative,
  246. NetLinkAddressDuplicate,
  247. NetLinkAddressConfigured,
  248. NetLinkAddressConfiguredStatic
  249. } NET_LINK_ADDRESS_STATE, *PNET_LINK_ADDRESS_STATE;
  250. typedef struct _NET_PROTOCOL_ENTRY NET_PROTOCOL_ENTRY, *PNET_PROTOCOL_ENTRY;
  251. typedef struct _NET_NETWORK_ENTRY NET_NETWORK_ENTRY, *PNET_NETWORK_ENTRY;
  252. typedef struct _NET_RECEIVE_CONTEXT NET_RECEIVE_CONTEXT, *PNET_RECEIVE_CONTEXT;
  253. /*++
  254. Structure Description:
  255. This structure defines packet size information.
  256. Members:
  257. HeaderSize - Stores the total size of the headers needed to send a packet.
  258. FooterSize - Stores the total size of the footers needed to send a packet.
  259. MaxPacketSize - Stores the maximum size of a packet that can be sent to the
  260. physical layer. This includes all headers and footers. This is limited
  261. by the protocol, network, and link for bound sockets, but is only
  262. limited by the protocol and network for unbound sockets.
  263. MinPacketSize - Stores the minimum size of a packet that can be sent to the
  264. physical layer. This includes all headers and footers. This is only
  265. ever limited by the device link layer.
  266. --*/
  267. typedef struct _NET_PACKET_SIZE_INFORMATION {
  268. ULONG HeaderSize;
  269. ULONG FooterSize;
  270. ULONG MaxPacketSize;
  271. ULONG MinPacketSize;
  272. } NET_PACKET_SIZE_INFORMATION, *PNET_PACKET_SIZE_INFORMATION;
  273. /*++
  274. Structure Description:
  275. This structure defines an entry in the list of link layer network addresses
  276. owned by the link.
  277. Members:
  278. ListEntry - Stores pointers to the next and previous addresses owned by the
  279. link.
  280. Network - Stores a pointer to the network associated with the link address
  281. entry. This contains an interface that can be used to drive network
  282. specific link address configuration (e.g. DHCP, NDP, DHCPv6).
  283. State - Stores the current state of the link address entry.
  284. Address - Stores the network address of the link.
  285. Subnet - Stores the network subnet mask of the link.
  286. DefaultGateway - Stores the default gateway network address for the link.
  287. DnsServer - Stores an array of network addresses of Domain Name Servers
  288. to try, in order.
  289. DnsServerCount - Stores the number of valid DNS servers in the array.
  290. PhysicalAddress - Stores the physical address of the link.
  291. LeaseServerAddress - Stores the network address of the server who provided
  292. the network address if it is a dynamic address.
  293. LeaseStartTime - Stores the time the lease on the network address began.
  294. LeaseEndTime - Stores the time the lease on the network address ends.
  295. --*/
  296. typedef struct _NET_LINK_ADDRESS_ENTRY {
  297. LIST_ENTRY ListEntry;
  298. PNET_NETWORK_ENTRY Network;
  299. volatile NET_LINK_ADDRESS_STATE State;
  300. NETWORK_ADDRESS Address;
  301. NETWORK_ADDRESS Subnet;
  302. NETWORK_ADDRESS DefaultGateway;
  303. NETWORK_ADDRESS DnsServer[NETWORK_DEVICE_MAX_DNS_SERVERS];
  304. ULONG DnsServerCount;
  305. NETWORK_ADDRESS PhysicalAddress;
  306. NETWORK_ADDRESS LeaseServerAddress;
  307. SYSTEM_TIME LeaseStartTime;
  308. SYSTEM_TIME LeaseEndTime;
  309. } NET_LINK_ADDRESS_ENTRY, *PNET_LINK_ADDRESS_ENTRY;
  310. /*++
  311. Structure Description:
  312. This structure defines information about a network packet.
  313. Members:
  314. ListEntry - Stores pointers to the next and previous network packets.
  315. Buffer - Stores the virtual address of the buffer.
  316. IoBuffer - Stores a pointer to the I/O buffer backing this buffer.
  317. BufferPhysicalAddress - Stores the physical address of the buffer.
  318. Flags - Stores a bitmask of network packet buffer flags. See
  319. NET_PACKET_FLAG_* for definitions.
  320. BufferSize - Stores the size of the buffer, in bytes.
  321. DataSize - Stores the size of the data, including the headers payload, and
  322. footers.
  323. DataOffset - Stores the offset from the beginning of the buffer to the
  324. beginning of the valid data. The next lower layer should put its own
  325. headers right before this offset.
  326. FooterOffset - Stores the offset from the beginning of the buffer to the
  327. beginning of the footer data (ie the location to store the first byte
  328. of new footer).
  329. --*/
  330. typedef struct _NET_PACKET_BUFFER {
  331. LIST_ENTRY ListEntry;
  332. PVOID Buffer;
  333. PIO_BUFFER IoBuffer;
  334. PHYSICAL_ADDRESS BufferPhysicalAddress;
  335. ULONG Flags;
  336. ULONG BufferSize;
  337. ULONG DataSize;
  338. ULONG DataOffset;
  339. ULONG FooterOffset;
  340. } NET_PACKET_BUFFER, *PNET_PACKET_BUFFER;
  341. /*++
  342. Struction Description:
  343. This structure defines a list of network packet buffers.
  344. Members:
  345. Head - Stores pointers to the first and last network packet buffers in the
  346. list.
  347. Count - Stores the total number of packets in the list.
  348. --*/
  349. typedef struct _NET_PACKET_LIST {
  350. LIST_ENTRY Head;
  351. UINTN Count;
  352. } NET_PACKET_LIST, *PNET_PACKET_LIST;
  353. typedef
  354. KSTATUS
  355. (*PNET_DEVICE_LINK_SEND) (
  356. PVOID DeviceContext,
  357. PNET_PACKET_LIST PacketList
  358. );
  359. /*++
  360. Routine Description:
  361. This routine sends data through the network.
  362. Arguments:
  363. DeviceContext - Supplies a pointer to the device context associated with
  364. the link down which this data is to be sent.
  365. PacketList - Supplies a pointer to a list of network packets to send. Data
  366. in these packets may be modified by this routine, but must not be used
  367. once this routine returns.
  368. Return Value:
  369. STATUS_SUCCESS if all packets were sent.
  370. STATUS_RESOURCE_IN_USE if some or all of the packets were dropped due to
  371. the hardware being backed up with too many packets to send.
  372. Other failure codes indicate that none of the packets were sent.
  373. --*/
  374. typedef
  375. KSTATUS
  376. (*PNET_DEVICE_LINK_GET_SET_INFORMATION) (
  377. PVOID DeviceContext,
  378. NET_LINK_INFORMATION_TYPE InformationType,
  379. PVOID Data,
  380. PUINTN DataSize,
  381. BOOL Set
  382. );
  383. /*++
  384. Routine Description:
  385. This routine gets or sets the network device layer's link information.
  386. Arguments:
  387. DeviceContext - Supplies a pointer to the device context associated with
  388. the link for which information is being set or queried.
  389. InformationType - Supplies the type of information being queried or set.
  390. Data - Supplies a pointer to the data buffer where the data is either
  391. returned for a get operation or given for a set operation.
  392. DataSize - Supplies a pointer that on input contains the size of the data
  393. buffer. On output, contains the required size of the data buffer.
  394. Set - Supplies a boolean indicating if this is a get operation (FALSE) or a
  395. set operation (TRUE).
  396. Return Value:
  397. Status code.
  398. --*/
  399. typedef
  400. VOID
  401. (*PNET_DEVICE_LINK_DESTROY_LINK) (
  402. PVOID DeviceContext
  403. );
  404. /*++
  405. Routine Description:
  406. This routine notifies the device layer that the networking core is in the
  407. process of destroying the link and will no longer call into the device for
  408. this link. This allows the device layer to release any context that was
  409. supporting the device link interface.
  410. Arguments:
  411. DeviceContext - Supplies a pointer to the device context associated with
  412. the link being destroyed.
  413. Return Value:
  414. None.
  415. --*/
  416. /*++
  417. Structure Description:
  418. This structure defines the interface to a device link from the core
  419. networking library.
  420. Members:
  421. Send - Stores a pointer to a function used to transmit data to the network.
  422. GetSetInformation - Supplies a pointer to a function used to get or set
  423. network link information.
  424. DestroyLink - Supplies a pointer to a function used to notify the device
  425. that the network link is no longer in use by the networking core and
  426. any link interface context can be destroyed.
  427. --*/
  428. typedef struct _NET_DEVICE_LINK_INTERFACE {
  429. PNET_DEVICE_LINK_SEND Send;
  430. PNET_DEVICE_LINK_GET_SET_INFORMATION GetSetInformation;
  431. PNET_DEVICE_LINK_DESTROY_LINK DestroyLink;
  432. } NET_DEVICE_LINK_INTERFACE, *PNET_DEVICE_LINK_INTERFACE;
  433. /*++
  434. Structure Description:
  435. This structure defines characteristics about a network link.
  436. Members:
  437. Version - Stores the version number of the structure. Set this to
  438. NET_LINK_PROPERTIES_VERSION.
  439. TransmitAlignment - Stores the alignment requirement for transmit buffers.
  440. Device - Stores a pointer to the physical layer device backing the link.
  441. DeviceContext - Stores a pointer to device-specific context on this link.
  442. PacketSizeInformation - Stores the packet size information that includes
  443. the maximum number of bytes that can be sent over the physical link and
  444. the header and footer sizes.
  445. Capabilities - Stores a bitmask of capabilities indicating whether or not
  446. certain features are supported by the link. See NET_LINK_CAPABILITY_*
  447. for definitions. This is a static field and does not describe which
  448. features are currently enabled.
  449. DataLinkType - Stores the type of the data link layer used by the network
  450. link.
  451. MaxPhysicalAddress - Stores the maximum physical address that the network
  452. controller can access.
  453. PhysicalAddress - Stores the original primary physical address of the link.
  454. Interface - Stores the list of functions used by the core networking
  455. library to call into the link.
  456. --*/
  457. typedef struct _NET_LINK_PROPERTIES {
  458. ULONG Version;
  459. ULONG TransmitAlignment;
  460. PDEVICE Device;
  461. PVOID DeviceContext;
  462. NET_PACKET_SIZE_INFORMATION PacketSizeInformation;
  463. ULONG Capabilities;
  464. NET_DOMAIN_TYPE DataLinkType;
  465. PHYSICAL_ADDRESS MaxPhysicalAddress;
  466. NETWORK_ADDRESS PhysicalAddress;
  467. NET_DEVICE_LINK_INTERFACE Interface;
  468. } NET_LINK_PROPERTIES, *PNET_LINK_PROPERTIES;
  469. /*++
  470. Structure Description:
  471. This structure defines a multicast group for a link.
  472. Members:
  473. ListEntry - Stores an entry into a link's list of multicast groups.
  474. LinkAddress - Stores a pointer to the link address on which the link is
  475. joined to the multicast group.
  476. JoinCount - Stores the number of times a join request has been made for
  477. this multicast group.
  478. Address - Stores the multicast address of the group.
  479. --*/
  480. typedef struct _NET_LINK_MULTICAST_GROUP {
  481. LIST_ENTRY ListEntry;
  482. PNET_LINK_ADDRESS_ENTRY LinkAddress;
  483. ULONG JoinCount;
  484. NETWORK_ADDRESS Address;
  485. } NET_LINK_MULTICAST_GROUP, *PNET_LINK_MULTICAST_GROUP;
  486. typedef struct _NET_DATA_LINK_ENTRY NET_DATA_LINK_ENTRY, *PNET_DATA_LINK_ENTRY;
  487. /*++
  488. Structure Description:
  489. This structure defines a network link, something that can actually send
  490. packets out onto the network.
  491. Members:
  492. ListEntry - Stores pointers to the next and previous network links
  493. available in the system.
  494. ReferenceCount - Stores the reference count of the link.
  495. QueuedLock - Stores a queued lock protecting access to various data
  496. structures in this structure. This lock must only be called at low
  497. level.
  498. LinkAddressArray - Stores an array of link layer address lists owned by
  499. this link. Each list contains addresses for each socket network type.
  500. For example, the IPv4 entry contains all the IPv4 addresses the link
  501. responds to (typically one). The list entries are of type
  502. NET_LINK_ADDRESS_ENTRY.
  503. LinkUp - Stores a boolean indicating whether the link is active (TRUE) or
  504. disconnected (FALSE).
  505. LinkSpeed - Stores the maximum speed of the link, in bits per second.
  506. DataLinkEntry - Stores a pointer to the data link entry to use for this
  507. link.
  508. DataLinkContext - Stores a pointer to a private context for the data link
  509. layer. This can be set directly during data link initialization.
  510. Properties - Stores the link properties.
  511. AddressTranslationEvent - Stores the event waited on when a new address
  512. translation is required.
  513. AddressTranslationTree - Stores the tree containing translations between
  514. network addresses and physical addresses, keyed by network address.
  515. MulticastGroupList - Stores a list of the multicast groups to which this
  516. link belongs.
  517. --*/
  518. typedef struct _NET_LINK {
  519. LIST_ENTRY ListEntry;
  520. volatile ULONG ReferenceCount;
  521. PQUEUED_LOCK QueuedLock;
  522. LIST_ENTRY LinkAddressArray[NetDomainSocketNetworkCount];
  523. BOOL LinkUp;
  524. ULONGLONG LinkSpeed;
  525. PNET_DATA_LINK_ENTRY DataLinkEntry;
  526. PVOID DataLinkContext;
  527. NET_LINK_PROPERTIES Properties;
  528. PKEVENT AddressTranslationEvent;
  529. RED_BLACK_TREE AddressTranslationTree;
  530. LIST_ENTRY MulticastGroupList;
  531. } NET_LINK, *PNET_LINK;
  532. typedef
  533. KSTATUS
  534. (*PNET_DATA_LINK_INITIALIZE_LINK) (
  535. PNET_LINK Link
  536. );
  537. /*++
  538. Routine Description:
  539. This routine initializes any pieces of information needed by the data link
  540. layer for a new link.
  541. Arguments:
  542. Link - Supplies a pointer to the new link.
  543. Return Value:
  544. Status code.
  545. --*/
  546. typedef
  547. VOID
  548. (*PNET_DATA_LINK_DESTROY_LINK) (
  549. PNET_LINK Link
  550. );
  551. /*++
  552. Routine Description:
  553. This routine allows the data link layer to tear down any state before a
  554. link is destroyed.
  555. Arguments:
  556. Link - Supplies a pointer to the dying link.
  557. Return Value:
  558. None.
  559. --*/
  560. typedef
  561. KSTATUS
  562. (*PNET_DATA_LINK_SEND) (
  563. PVOID DataLinkContext,
  564. PNET_PACKET_LIST PacketList,
  565. PNETWORK_ADDRESS SourcePhysicalAddress,
  566. PNETWORK_ADDRESS DestinationPhysicalAddress,
  567. ULONG ProtocolNumber
  568. );
  569. /*++
  570. Routine Description:
  571. This routine sends data through the data link layer and out the link.
  572. Arguments:
  573. DataLinkContext - Supplies a pointer to the data link context for the
  574. link on which to send the data.
  575. PacketList - Supplies a pointer to a list of network packets to send. Data
  576. in these packets may be modified by this routine, but must not be used
  577. once this routine returns.
  578. SourcePhysicalAddress - Supplies a pointer to the source (local) physical
  579. network address.
  580. DestinationPhysicalAddress - Supplies the optional physical address of the
  581. destination, or at least the next hop. If NULL is provided, then the
  582. packets will be sent to the data link layer's broadcast address.
  583. ProtocolNumber - Supplies the protocol number of the data inside the data
  584. link header.
  585. Return Value:
  586. Status code.
  587. --*/
  588. typedef
  589. VOID
  590. (*PNET_DATA_LINK_PROCESS_RECEIVED_PACKET) (
  591. PVOID DataLinkContext,
  592. PNET_PACKET_BUFFER Packet
  593. );
  594. /*++
  595. Routine Description:
  596. This routine is called to process a received data link layer packet.
  597. Arguments:
  598. DataLinkContext - Supplies a pointer to the data link context for the link
  599. that received the packet.
  600. Packet - Supplies a pointer to a structure describing the incoming packet.
  601. This structure may be used as a scratch space while this routine
  602. executes and the packet travels up the stack, but will not be accessed
  603. after this routine returns.
  604. Return Value:
  605. None. When the function returns, the memory associated with the packet may
  606. be reclaimed and reused.
  607. --*/
  608. typedef
  609. KSTATUS
  610. (*PNET_DATA_LINK_CONVERT_TO_PHYSICAL_ADDRESS) (
  611. PNETWORK_ADDRESS NetworkAddress,
  612. PNETWORK_ADDRESS PhysicalAddress,
  613. NET_ADDRESS_TYPE NetworkAddressType
  614. );
  615. /*++
  616. Routine Description:
  617. This routine converts the given network address to a physical layer address
  618. based on the provided network address type.
  619. Arguments:
  620. NetworkAddress - Supplies a pointer to the network layer address to convert.
  621. PhysicalAddress - Supplies a pointer to an address that receives the
  622. converted physical layer address.
  623. NetworkAddressType - Supplies the classified type of the given network
  624. address, which aids in conversion.
  625. Return Value:
  626. Status code.
  627. --*/
  628. typedef
  629. ULONG
  630. (*PNET_DATA_LINK_PRINT_ADDRESS) (
  631. PNETWORK_ADDRESS Address,
  632. PSTR Buffer,
  633. ULONG BufferLength
  634. );
  635. /*++
  636. Routine Description:
  637. This routine is called to convert a network address into a string, or
  638. determine the length of the buffer needed to convert an address into a
  639. string.
  640. Arguments:
  641. Address - Supplies an optional pointer to a network address to convert to
  642. a string.
  643. Buffer - Supplies an optional pointer where the string representation of
  644. the address will be returned.
  645. BufferLength - Supplies the length of the supplied buffer, in bytes.
  646. Return Value:
  647. Returns the maximum length of any address if no network address is
  648. supplied.
  649. Returns the actual length of the network address string if a network address
  650. was supplied, including the null terminator.
  651. --*/
  652. typedef
  653. VOID
  654. (*PNET_DATA_LINK_GET_PACKET_SIZE_INFORMATION) (
  655. PVOID DataLinkContext,
  656. PNET_PACKET_SIZE_INFORMATION PacketSizeInformation,
  657. ULONG Flags
  658. );
  659. /*++
  660. Routine Description:
  661. This routine gets the current packet size information for the given link.
  662. As the number of required headers can be different for each link, the
  663. packet size information is not a constant for an entire data link layer.
  664. Arguments:
  665. DataLinkContext - Supplies a pointer to the data link context of the link
  666. whose packet size information is being queried.
  667. PacketSizeInformation - Supplies a pointer to a structure that receives the
  668. link's data link layer packet size information.
  669. Flags - Supplies a bitmask of flags indicating which packet size
  670. information is desired. See NET_PACKET_SIZE_FLAG_* for definitions.
  671. Return Value:
  672. None.
  673. --*/
  674. /*++
  675. Structure Description:
  676. This structure defines the interface to the data link from the core
  677. networking library.
  678. Members:
  679. InitializeLink - Stores a pointer to a function called when a new link
  680. is created.
  681. DestroyLink - Stores a pointer to a function called before a link is
  682. destroyed.
  683. Send - Stores a pointer to a function used to transmit data to the network.
  684. ProcessReceivedPacket - Stores a pointer to a function used to process
  685. received data link layer packets.
  686. ConvertToPhysicalAddress - Stores a pointer to a function used to convert a
  687. network layer address into a data link layer physical address.
  688. PrintAddress - Stores a pointer to a function used to convert a data link
  689. address into a string representation.
  690. GetPacketSizeInformation - Stores a pointer to a function that returns the
  691. required packet size information for a link.
  692. --*/
  693. typedef struct _NET_DATA_LINK_INTERFACE {
  694. PNET_DATA_LINK_INITIALIZE_LINK InitializeLink;
  695. PNET_DATA_LINK_DESTROY_LINK DestroyLink;
  696. PNET_DATA_LINK_SEND Send;
  697. PNET_DATA_LINK_PROCESS_RECEIVED_PACKET ProcessReceivedPacket;
  698. PNET_DATA_LINK_CONVERT_TO_PHYSICAL_ADDRESS ConvertToPhysicalAddress;
  699. PNET_DATA_LINK_PRINT_ADDRESS PrintAddress;
  700. PNET_DATA_LINK_GET_PACKET_SIZE_INFORMATION GetPacketSizeInformation;
  701. } NET_DATA_LINK_INTERFACE, *PNET_DATA_LINK_INTERFACE;
  702. /*++
  703. Structure Description:
  704. This structure defines a data link entry.
  705. Members:
  706. ListEntry - Stores pointers to the next and previous data link entries,
  707. used internally by the core network library.
  708. Domain - Stores the network domain type this data link implements.
  709. Interface - Stores the interface presented to the core networking library
  710. for this data link.
  711. --*/
  712. struct _NET_DATA_LINK_ENTRY {
  713. LIST_ENTRY ListEntry;
  714. NET_DOMAIN_TYPE Domain;
  715. NET_DATA_LINK_INTERFACE Interface;
  716. };
  717. /*++
  718. Structure Description:
  719. This structure defines a translation between a network address and a
  720. physical one.
  721. Members:
  722. Node - Stores the red black tree information for this node.
  723. ReferenceCount - Stores the reference count on the translation entry.
  724. NetworkAddress - Stores the network address, the key for the red black
  725. tree node.
  726. PhysicalAddress - Stores the physical address that corresponds to the
  727. network address.
  728. --*/
  729. typedef struct _NET_TRANSLATION_ENTRY {
  730. RED_BLACK_TREE_NODE Node;
  731. volatile ULONG ReferenceCount;
  732. NETWORK_ADDRESS NetworkAddress;
  733. NETWORK_ADDRESS PhysicalAddress;
  734. } NET_TRANSLATION_ENTRY, *PNET_TRANSLATION_ENTRY;
  735. /*++
  736. Structure Description:
  737. This structure defines a request to lookup an address translation entry for
  738. the given query address. The caller is responsible for releasing the
  739. reference on the translation entry, if returned.
  740. Members:
  741. Link - Stores a pointer to the link on which to lookup the query address.
  742. LinkAddress - Stores a pointer to the link address entry over which to
  743. communicate any network requests that need to be sent in order to
  744. translate the address.
  745. QueryAddress - Stores a pointer to the network address to translation.
  746. Translation - Stores a pointer to the found translation entry on success,
  747. or NULL on failure.
  748. --*/
  749. typedef struct _NET_TRANSLATION_REQUEST {
  750. PNET_LINK Link;
  751. PNET_LINK_ADDRESS_ENTRY LinkAddress;
  752. PNETWORK_ADDRESS QueryAddress;
  753. PNET_TRANSLATION_ENTRY Translation;
  754. } NET_TRANSLATION_REQUEST, *PNET_TRANSLATION_REQUEST;
  755. /*++
  756. Structure Description:
  757. This structure defines the link information associated with a local address.
  758. Members:
  759. Link - Stores a pointer to the link that owns the local address.
  760. LinkAdress - Stores a pointer to the link address entry that owns the local
  761. address.
  762. ReceiveAddress - Stores the local address on which packets can be received.
  763. SendAddress - Stores the local address from which packets will be sent.
  764. --*/
  765. typedef struct _NET_LINK_LOCAL_ADDRESS {
  766. PNET_LINK Link;
  767. PNET_LINK_ADDRESS_ENTRY LinkAddress;
  768. NETWORK_ADDRESS ReceiveAddress;
  769. NETWORK_ADDRESS SendAddress;
  770. } NET_LINK_LOCAL_ADDRESS, *PNET_LINK_LOCAL_ADDRESS;
  771. /*++
  772. Structure Description:
  773. This structure defines a multicast group join/leave request.
  774. Members:
  775. MulticastAddress - Stores the multicast address of the group to join or
  776. leave.
  777. InterfaceAddress - Stores the address of the link interface over which the
  778. multicast join/leave is requested.
  779. InterfaceId- Stores the ID of the link interface over which the multicast
  780. join/leave is requested.
  781. --*/
  782. typedef struct _NET_SOCKET_MULTICAST_REQUEST {
  783. NETWORK_ADDRESS MulticastAddress;
  784. NETWORK_ADDRESS InterfaceAddress;
  785. DEVICE_ID InterfaceId;
  786. } NET_SOCKET_MULTICAST_REQUEST, *PNET_SOCKET_MULTICAST_REQUEST;
  787. /*++
  788. Structure Description:
  789. This structure defines a multicast group for a socket.
  790. Members:
  791. ListEntry - Stores pointers to the previous and next multicast groups in
  792. the socket's list.
  793. Link - Supplies a pointer to the network link to which the multicast group
  794. is attached.
  795. LinkAddress - Supplies a pointer to the link address entry with which the
  796. multicast group is associated.
  797. MulitcastAddress - Stores the multicast address of the group.
  798. --*/
  799. typedef struct _NET_SOCKET_MULTICAST_GROUP {
  800. LIST_ENTRY ListEntry;
  801. PNET_LINK Link;
  802. PNET_LINK_ADDRESS_ENTRY LinkAddress;
  803. NETWORK_ADDRESS MulticastAddress;
  804. } NET_SOCKET_MULTICAST_GROUP, *PNET_SOCKET_MULTICAST_GROUP;
  805. /*++
  806. Structure Description:
  807. This structure defines a core networking socket link override. This stores
  808. all the socket and link specific information needed to send a packet. This
  809. can be used to send data from a link on behalf of a socket if the socket
  810. is not yet bound to a link.
  811. Members:
  812. LinkInformation - Stores the local address and its associated link and link
  813. address entry.
  814. PacketSizeInformation - Stores the packet size information bound by the
  815. protocol, network and link layers.
  816. --*/
  817. typedef struct _NET_SOCKET_LINK_OVERRIDE {
  818. NET_LINK_LOCAL_ADDRESS LinkInformation;
  819. NET_PACKET_SIZE_INFORMATION PacketSizeInformation;
  820. } NET_SOCKET_LINK_OVERRIDE, *PNET_SOCKET_LINK_OVERRIDE;
  821. /*++
  822. Structure Description:
  823. This structure defines a core networking library socket.
  824. Members:
  825. KernelSocket - Stores the common parameters recognized by the kernel.
  826. Protocol - Stores a pointer to the protocol entry responsible for this
  827. socket.
  828. Network - Stores a pointer to the network layer entry responsible for this
  829. socket.
  830. LocalReceiveAddress - Stores the local address to which the socket is bound
  831. to for receiving packets. This may be the any address or broadcast
  832. address.
  833. LocalSendAddress - Stores the local address to which the socket is bound to
  834. for sending packets. This must be a unicast address.
  835. RemoteAddress - Stores the remote address of this connection.
  836. RemotePhysicalAddress - Stores the remote physical address of this
  837. connection.
  838. RemoteTranslation - Stores an optional pointer to the remote address
  839. translation entry in use by the socket. When present, it should hold
  840. the same remote address and remote physical address as stored in the
  841. socket. The remote addresses are still stored separately because
  842. multicast and broadcast addresses aren't in the translation cache. It
  843. does not make sense to cache them as it's a constant-time converstion
  844. between a multicast/broadcast network address and its physical address.
  845. TreeEntry - Stores the information about this socket in the tree of
  846. sockets (which is either on the link itself or global).
  847. BindingType - Stores the type of binding for this socket (unbound, locally
  848. bound, or fully bound).
  849. Flags - Stores a bitmask of network socket flags. See NET_SOCKET_FLAG_*
  850. for definitions.
  851. PacketSizeInformation - Stores the packet size information bound by the
  852. protocol, network and link layers if the socket is locally bound. For
  853. unbound sockets, this stores the size information limited by only the
  854. protocol and network layers.
  855. UnboundPacketSizeInformation - Stores the packet size information bound by
  856. only the protocol and network layers.
  857. LastError - Stores the last error encountered by this socket.
  858. Link - Stores a pointer to the link this socket is associated with.
  859. LinkAddress - Stores the link address information for the given socket.
  860. SendPacketCount - Stores the number of packets sent on this socket.
  861. MaxIncomingConnections - Stores the maximum number of pending but not yet
  862. accepted connections that are allowed to accumulate before connections
  863. are refused. In the sockets API this is known as the backlog count.
  864. HopLimit - Stores the hop limit (a.k.a. time-to-live) that is to be set in
  865. the IP headers of every packet sent by this socket.
  866. DifferentiatedServicesCodePoint - Stores the differentiated services code
  867. point that is to be set in the IP header of every packet sent by this
  868. socket.
  869. MulticastHopLimit - Stores the hop limit (a.k.a. time-to-live) that is to
  870. be set in the IP header of every multicast packet sent by this socket.
  871. MulticastInterface - Stores the interface over which to send all multicast
  872. packets. If this is not initialized, then a default interface is chosen
  873. just as it would be for unicast packets.
  874. MulticastLock - Supplies a pointer to the queued lock that protects access
  875. to the multicast information.
  876. MulticastGroupList - Stores the head of the list of multicast groups to
  877. which the socket belongs.
  878. --*/
  879. typedef struct _NET_SOCKET {
  880. SOCKET KernelSocket;
  881. PNET_PROTOCOL_ENTRY Protocol;
  882. PNET_NETWORK_ENTRY Network;
  883. NETWORK_ADDRESS LocalReceiveAddress;
  884. NETWORK_ADDRESS LocalSendAddress;
  885. NETWORK_ADDRESS RemoteAddress;
  886. NETWORK_ADDRESS RemotePhysicalAddress;
  887. PNET_TRANSLATION_ENTRY RemoteTranslation;
  888. RED_BLACK_TREE_NODE TreeEntry;
  889. NET_SOCKET_BINDING_TYPE BindingType;
  890. volatile ULONG Flags;
  891. NET_PACKET_SIZE_INFORMATION PacketSizeInformation;
  892. NET_PACKET_SIZE_INFORMATION UnboundPacketSizeInformation;
  893. volatile KSTATUS LastError;
  894. PNET_LINK Link;
  895. PNET_LINK_ADDRESS_ENTRY LinkAddress;
  896. ULONG SendPacketCount;
  897. ULONG MaxIncomingConnections;
  898. UCHAR HopLimit;
  899. UCHAR DifferentiatedServicesCodePoint;
  900. UCHAR MulticastHopLimit;
  901. NET_SOCKET_LINK_OVERRIDE MulticastInterface;
  902. volatile PQUEUED_LOCK MulticastLock;
  903. LIST_ENTRY MulticastGroupList;
  904. } NET_SOCKET, *PNET_SOCKET;
  905. typedef
  906. KSTATUS
  907. (*PNET_PROTOCOL_CREATE_SOCKET) (
  908. PNET_PROTOCOL_ENTRY ProtocolEntry,
  909. PNET_NETWORK_ENTRY NetworkEntry,
  910. ULONG NetworkProtocol,
  911. PNET_SOCKET *NewSocket,
  912. ULONG Phase
  913. );
  914. /*++
  915. Routine Description:
  916. This routine allocates resources associated with a new socket. The protocol
  917. driver is responsible for allocating the structure (with additional length
  918. for any of its context). The core networking library will fill in the
  919. common header when this routine returns.
  920. Arguments:
  921. ProtocolEntry - Supplies a pointer to the protocol information.
  922. NetworkEntry - Supplies a pointer to the network information.
  923. NetworkProtocol - Supplies the raw protocol value for this socket used on
  924. the network. This value is network specific.
  925. NewSocket - Supplies a pointer where a pointer to a newly allocated
  926. socket structure will be returned. The caller is responsible for
  927. allocating the socket (and potentially a larger structure for its own
  928. context). The core network library will fill in the standard socket
  929. structure after this routine returns. In phase 1, this will contain
  930. a pointer to the socket allocated during phase 0.
  931. Phase - Supplies the socket creation phase. Phase 0 is the allocation phase
  932. and phase 1 is the advanced initialization phase, which is invoked
  933. after net core is done filling out common portions of the socket
  934. structure.
  935. Return Value:
  936. Status code.
  937. --*/
  938. typedef
  939. VOID
  940. (*PNET_PROTOCOL_DESTROY_SOCKET) (
  941. PNET_SOCKET Socket
  942. );
  943. /*++
  944. Routine Description:
  945. This routine destroys resources associated with an open socket, officially
  946. marking the end of the kernel and core networking library's knowledge of
  947. this structure.
  948. Arguments:
  949. Socket - Supplies a pointer to the socket to destroy. The core networking
  950. library will have already destroyed any resources inside the common
  951. header, the protocol should not reach through any pointers inside the
  952. socket header except the protocol and network entries.
  953. Return Value:
  954. None. This routine is responsible for freeing the memory associated with
  955. the socket structure itself.
  956. --*/
  957. typedef
  958. KSTATUS
  959. (*PNET_PROTOCOL_BIND_TO_ADDRESS) (
  960. PNET_SOCKET Socket,
  961. PNET_LINK Link,
  962. PNETWORK_ADDRESS Address
  963. );
  964. /*++
  965. Routine Description:
  966. This routine binds the given socket to the specified network address.
  967. Usually this is a no-op for the protocol, it's simply responsible for
  968. passing the request down to the network layer.
  969. Arguments:
  970. Socket - Supplies a pointer to the socket to bind.
  971. Link - Supplies an optional pointer to a link to bind to.
  972. Address - Supplies a pointer to the address to bind the socket to.
  973. Return Value:
  974. Status code.
  975. --*/
  976. typedef
  977. KSTATUS
  978. (*PNET_PROTOCOL_LISTEN) (
  979. PNET_SOCKET Socket
  980. );
  981. /*++
  982. Routine Description:
  983. This routine adds a bound socket to the list of listening sockets,
  984. officially allowing clients to attempt to connect to it.
  985. Arguments:
  986. Socket - Supplies a pointer to the socket to mark as listning.
  987. Return Value:
  988. Status code.
  989. --*/
  990. typedef
  991. KSTATUS
  992. (*PNET_PROTOCOL_ACCEPT) (
  993. PNET_SOCKET Socket,
  994. PIO_HANDLE *NewConnectionSocket,
  995. PNETWORK_ADDRESS RemoteAddress
  996. );
  997. /*++
  998. Routine Description:
  999. This routine accepts an incoming connection on a listening connection-based
  1000. socket.
  1001. Arguments:
  1002. Socket - Supplies a pointer to the socket to accept a connection from.
  1003. NewConnectionSocket - Supplies a pointer where a new socket will be
  1004. returned that represents the accepted connection with the remote
  1005. host.
  1006. RemoteAddress - Supplies a pointer where the address of the connected
  1007. remote host will be returned.
  1008. Return Value:
  1009. Status code.
  1010. --*/
  1011. typedef
  1012. KSTATUS
  1013. (*PNET_PROTOCOL_CONNECT) (
  1014. PNET_SOCKET Socket,
  1015. PNETWORK_ADDRESS Address
  1016. );
  1017. /*++
  1018. Routine Description:
  1019. This routine attempts to make an outgoing connection to a server.
  1020. Arguments:
  1021. Socket - Supplies a pointer to the socket to use for the connection.
  1022. Address - Supplies a pointer to the address to connect to.
  1023. Return Value:
  1024. Status code.
  1025. --*/
  1026. typedef
  1027. KSTATUS
  1028. (*PNET_PROTOCOL_CLOSE) (
  1029. PNET_SOCKET Socket
  1030. );
  1031. /*++
  1032. Routine Description:
  1033. This routine closes a socket connection.
  1034. Arguments:
  1035. Socket - Supplies a pointer to the socket to shut down.
  1036. Return Value:
  1037. Status code.
  1038. --*/
  1039. typedef
  1040. KSTATUS
  1041. (*PNET_PROTOCOL_SHUTDOWN) (
  1042. PNET_SOCKET Socket,
  1043. ULONG ShutdownType
  1044. );
  1045. /*++
  1046. Routine Description:
  1047. This routine shuts down communication with a given socket.
  1048. Arguments:
  1049. Socket - Supplies a pointer to the socket.
  1050. ShutdownType - Supplies the shutdown type to perform. See the
  1051. SOCKET_SHUTDOWN_* definitions.
  1052. Return Value:
  1053. Status code.
  1054. --*/
  1055. typedef
  1056. KSTATUS
  1057. (*PNET_PROTOCOL_SEND) (
  1058. BOOL FromKernelMode,
  1059. PNET_SOCKET Socket,
  1060. PSOCKET_IO_PARAMETERS Parameters,
  1061. PIO_BUFFER IoBuffer
  1062. );
  1063. /*++
  1064. Routine Description:
  1065. This routine sends the given data buffer through the network using a
  1066. specific protocol.
  1067. Arguments:
  1068. FromKernelMode - Supplies a boolean indicating whether the request is
  1069. coming from kernel mode (TRUE) or user mode (FALSE).
  1070. Socket - Supplies a pointer to the socket to send the data to.
  1071. Parameters - Supplies a pointer to the socket I/O parameters. This will
  1072. always be a kernel mode pointer.
  1073. IoBuffer - Supplies a pointer to the I/O buffer containing the data to
  1074. send.
  1075. Return Value:
  1076. Status code.
  1077. --*/
  1078. typedef
  1079. VOID
  1080. (*PNET_PROTOCOL_PROCESS_RECEIVED_DATA) (
  1081. PNET_RECEIVE_CONTEXT ReceiveContext
  1082. );
  1083. /*++
  1084. Routine Description:
  1085. This routine is called to process a received packet.
  1086. Arguments:
  1087. ReceiveContext - Supplies a pointer to the receive context that stores the
  1088. link, packet, network, protocol, and source and destination addresses.
  1089. Return Value:
  1090. None. When the function returns, the memory associated with the packet may
  1091. be reclaimed and reused.
  1092. --*/
  1093. typedef
  1094. KSTATUS
  1095. (*PNET_PROTOCOL_PROCESS_RECEIVED_SOCKET_DATA) (
  1096. PNET_SOCKET Socket,
  1097. PNET_RECEIVE_CONTEXT ReceiveContext
  1098. );
  1099. /*++
  1100. Routine Description:
  1101. This routine is called for a particular socket to process a received packet
  1102. that was sent to it.
  1103. Arguments:
  1104. Socket - Supplies a pointer to the socket that received the packet.
  1105. ReceiveContext - Supplies a pointer to the receive context that stores the
  1106. link, packet, network, protocol, and source and destination addresses.
  1107. Return Value:
  1108. Status code.
  1109. --*/
  1110. typedef
  1111. KSTATUS
  1112. (*PNET_PROTOCOL_RECEIVE) (
  1113. BOOL FromKernelMode,
  1114. PNET_SOCKET Socket,
  1115. PSOCKET_IO_PARAMETERS Parameters,
  1116. PIO_BUFFER IoBuffer
  1117. );
  1118. /*++
  1119. Routine Description:
  1120. This routine is called by the user to receive data from the socket on a
  1121. particular protocol.
  1122. Arguments:
  1123. FromKernelMode - Supplies a boolean indicating whether the request is
  1124. coming from kernel mode (TRUE) or user mode (FALSE).
  1125. Socket - Supplies a pointer to the socket to receive data from.
  1126. Parameters - Supplies a pointer to the socket I/O parameters.
  1127. IoBuffer - Supplies a pointer to the I/O buffer where the received data
  1128. will be returned.
  1129. Return Value:
  1130. STATUS_SUCCESS if any bytes were read.
  1131. STATUS_TIMEOUT if the request timed out.
  1132. STATUS_BUFFER_TOO_SMALL if the incoming datagram was too large for the
  1133. buffer. The remainder of the datagram is discarded in this case.
  1134. Other error codes on other failures.
  1135. --*/
  1136. typedef
  1137. KSTATUS
  1138. (*PNET_PROTOCOL_GET_SET_INFORMATION) (
  1139. PNET_SOCKET Socket,
  1140. SOCKET_INFORMATION_TYPE InformationType,
  1141. UINTN Option,
  1142. PVOID Data,
  1143. PUINTN DataSize,
  1144. BOOL Set
  1145. );
  1146. /*++
  1147. Routine Description:
  1148. This routine gets or sets properties of the given socket.
  1149. Arguments:
  1150. Socket - Supplies a pointer to the socket to get or set information for.
  1151. InformationType - Supplies the socket information type category to which
  1152. specified option belongs.
  1153. Option - Supplies the option to get or set, which is specific to the
  1154. information type. The type of this value is generally
  1155. SOCKET_<information_type>_OPTION.
  1156. Data - Supplies a pointer to the data buffer where the data is either
  1157. returned for a get operation or given for a set operation.
  1158. DataSize - Supplies a pointer that on input constains the size of the data
  1159. buffer. On output, this contains the required size of the data buffer.
  1160. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  1161. a set operation (TRUE).
  1162. Return Value:
  1163. STATUS_SUCCESS on success.
  1164. STATUS_INVALID_PARAMETER if the information type is incorrect.
  1165. STATUS_BUFFER_TOO_SMALL if the data buffer is too small to receive the
  1166. requested option.
  1167. STATUS_NOT_SUPPORTED_BY_PROTOCOL if the socket option is not supported by
  1168. the socket.
  1169. STATUS_NOT_HANDLED if the protocol does not override the default behavior
  1170. for a basic socket option.
  1171. --*/
  1172. typedef
  1173. KSTATUS
  1174. (*PNET_PROTOCOL_USER_CONTROL) (
  1175. PNET_SOCKET Socket,
  1176. ULONG CodeNumber,
  1177. BOOL FromKernelMode,
  1178. PVOID ContextBuffer,
  1179. UINTN ContextBufferSize
  1180. );
  1181. /*++
  1182. Routine Description:
  1183. This routine handles user control requests destined for a socket.
  1184. Arguments:
  1185. Socket - Supplies a pointer to the socket.
  1186. CodeNumber - Supplies the minor code of the request.
  1187. FromKernelMode - Supplies a boolean indicating whether or not this request
  1188. (and the buffer associated with it) originates from user mode (FALSE)
  1189. or kernel mode (TRUE).
  1190. ContextBuffer - Supplies a pointer to the context buffer allocated by the
  1191. caller for the request.
  1192. ContextBufferSize - Supplies the size of the supplied context buffer.
  1193. Return Value:
  1194. Status code.
  1195. --*/
  1196. /*++
  1197. Structure Description:
  1198. This structure defines interface between the core networking library and
  1199. a network protocol.
  1200. Members:
  1201. CreateSocket - Stores a pointer to a function that creates a new socket.
  1202. DestroySocket - Stores a pointer to a function that destroys all resources
  1203. associated with a socket, called when the socket's reference count
  1204. drops to zero.
  1205. BindToAddress - Stores a pointer to a function that binds an open but
  1206. unbound socket to a particular network address.
  1207. Listen - Stores a pointer to a function that starts the socket listening
  1208. for incoming connections.
  1209. Accept - Stores a pointer to a function that accepts an incoming connection
  1210. from a remote host on a listening socket.
  1211. Connect - Stores a pointer to a function used to establish a connection with
  1212. a remote server.
  1213. Close - Stores a pointer to a function used to shut down and close a
  1214. connection.
  1215. Shutdown - Stores a pointer to a function used to shut down a connection.
  1216. Send - Stores a pointer to a function used to send data to a connection.
  1217. ProcessReceivedData - Stores a pointer to a function called when a packet
  1218. is received from the network.
  1219. ProcessReceivedSocketData - Stores a pointer to a function that processes a
  1220. packet targeting a specific socket.
  1221. Receive - Stores a pointer to a function called by the user to receive
  1222. data from the socket.
  1223. GetSetInformation - Stores a pointer to a function used to get or set
  1224. socket information.
  1225. UserControl - Stores a pointer to a function used to respond to user
  1226. control (ioctl) requests.
  1227. --*/
  1228. typedef struct _NET_PROTOCOL_INTERFACE {
  1229. PNET_PROTOCOL_CREATE_SOCKET CreateSocket;
  1230. PNET_PROTOCOL_DESTROY_SOCKET DestroySocket;
  1231. PNET_PROTOCOL_BIND_TO_ADDRESS BindToAddress;
  1232. PNET_PROTOCOL_LISTEN Listen;
  1233. PNET_PROTOCOL_ACCEPT Accept;
  1234. PNET_PROTOCOL_CONNECT Connect;
  1235. PNET_PROTOCOL_CLOSE Close;
  1236. PNET_PROTOCOL_SHUTDOWN Shutdown;
  1237. PNET_PROTOCOL_SEND Send;
  1238. PNET_PROTOCOL_PROCESS_RECEIVED_DATA ProcessReceivedData;
  1239. PNET_PROTOCOL_PROCESS_RECEIVED_SOCKET_DATA ProcessReceivedSocketData;
  1240. PNET_PROTOCOL_RECEIVE Receive;
  1241. PNET_PROTOCOL_GET_SET_INFORMATION GetSetInformation;
  1242. PNET_PROTOCOL_USER_CONTROL UserControl;
  1243. } NET_PROTOCOL_INTERFACE, *PNET_PROTOCOL_INTERFACE;
  1244. /*++
  1245. Structure Description:
  1246. This structure defines a network protocol entry.
  1247. Members:
  1248. ListEntry - Stores pointers to the next and previous protocol entries, used
  1249. internally by the core networking library.
  1250. Type - Stores the connection type this protocol implements.
  1251. ParentProtocolNumber - Stores the protocol number in the parent layer's
  1252. protocol.
  1253. Flags - Stores a bitmask of protocol flags. See NET_PROTOCOL_FLAG_* for
  1254. definitions.
  1255. LastSocket - Stores a pointer to the last socket that received a packet.
  1256. SocketLock - Stores a pointer to a shared exclusive lock that protects the
  1257. socket trees.
  1258. SocketTree - Stores an array of Red Black Trees, one each for fully bound,
  1259. locally bound, and unbound sockets.
  1260. Interface - Stores the interface presented to the kernel for this type of
  1261. socket.
  1262. --*/
  1263. struct _NET_PROTOCOL_ENTRY {
  1264. LIST_ENTRY ListEntry;
  1265. NET_SOCKET_TYPE Type;
  1266. ULONG ParentProtocolNumber;
  1267. ULONG Flags;
  1268. volatile PNET_SOCKET LastSocket;
  1269. PSHARED_EXCLUSIVE_LOCK SocketLock;
  1270. RED_BLACK_TREE SocketTree[SocketBindingTypeCount];
  1271. NET_PROTOCOL_INTERFACE Interface;
  1272. };
  1273. /*++
  1274. Structure Description:
  1275. This structure defines a request to join or leave a multicast group. It is
  1276. supplies to the network layer, as most networks have a specific protocol
  1277. used to join or leave a multicast group.
  1278. Members:
  1279. Link - Stores a pointer to the link on which to join the multicast group or
  1280. the link to leave the multicast group.
  1281. LinkAddress - Stores a pointer to the link address entry on which to join
  1282. the multicast group or the link address entry to leave the multicast
  1283. group.
  1284. MulticastAddress - Stores a pointer to the address of the multicast group
  1285. to join or leave.
  1286. --*/
  1287. typedef struct _NET_NETWORK_MULTICAST_REQUEST {
  1288. PNET_LINK Link;
  1289. PNET_LINK_ADDRESS_ENTRY LinkAddress;
  1290. PNETWORK_ADDRESS MulticastAddress;
  1291. } NET_NETWORK_MULTICAST_REQUEST, *PNET_NETWORK_MULTICAST_REQUEST;
  1292. typedef
  1293. KSTATUS
  1294. (*PNET_NETWORK_INITIALIZE_LINK) (
  1295. PNET_LINK Link
  1296. );
  1297. /*++
  1298. Routine Description:
  1299. This routine initializes any pieces of information needed by the network
  1300. layer for a new link.
  1301. Arguments:
  1302. Link - Supplies a pointer to the new link.
  1303. Return Value:
  1304. Status code.
  1305. --*/
  1306. typedef
  1307. VOID
  1308. (*PNET_NETWORK_DESTROY_LINK) (
  1309. PNET_LINK Link
  1310. );
  1311. /*++
  1312. Routine Description:
  1313. This routine allows the network layer to tear down any state before a link
  1314. is destroyed.
  1315. Arguments:
  1316. Link - Supplies a pointer to the dying link.
  1317. Return Value:
  1318. None.
  1319. --*/
  1320. typedef
  1321. KSTATUS
  1322. (*PNET_NETWORK_INITIALIZE_SOCKET) (
  1323. PNET_PROTOCOL_ENTRY ProtocolEntry,
  1324. PNET_NETWORK_ENTRY NetworkEntry,
  1325. ULONG NetworkProtocol,
  1326. PNET_SOCKET NewSocket
  1327. );
  1328. /*++
  1329. Routine Description:
  1330. This routine initializes any pieces of information needed by the network
  1331. layer for the socket. The core networking library will fill in the common
  1332. header when this routine returns.
  1333. Arguments:
  1334. ProtocolEntry - Supplies a pointer to the protocol information.
  1335. NetworkEntry - Supplies a pointer to the network information.
  1336. NetworkProtocol - Supplies the raw protocol value for this socket used on
  1337. the network. This value is network specific.
  1338. NewSocket - Supplies a pointer to the new socket. The network layer should
  1339. at the very least add any needed header size.
  1340. Return Value:
  1341. Status code.
  1342. --*/
  1343. typedef
  1344. VOID
  1345. (*PNET_NETWORK_DESTROY_SOCKET) (
  1346. PNET_SOCKET Socket
  1347. );
  1348. /*++
  1349. Routine Description:
  1350. This routine destroys any pieces allocated by the network layer for the
  1351. socket.
  1352. Arguments:
  1353. Socket - Supplies a pointer to the socket to destroy.
  1354. Return Value:
  1355. None.
  1356. --*/
  1357. typedef
  1358. KSTATUS
  1359. (*PNET_NETWORK_BIND_TO_ADDRESS) (
  1360. PNET_SOCKET Socket,
  1361. PNET_LINK Link,
  1362. PNETWORK_ADDRESS Address,
  1363. ULONG Flags
  1364. );
  1365. /*++
  1366. Routine Description:
  1367. This routine binds the given socket to the specified network address.
  1368. Arguments:
  1369. Socket - Supplies a pointer to the socket to bind.
  1370. Link - Supplies an optional pointer to a link to bind to.
  1371. Address - Supplies a pointer to the address to bind the socket to.
  1372. Flags - Supplies a bitmask of binding flags. See NET_SOCKET_BINDING_FLAG_*
  1373. for definitions.
  1374. Return Value:
  1375. Status code.
  1376. --*/
  1377. typedef
  1378. KSTATUS
  1379. (*PNET_NETWORK_LISTEN) (
  1380. PNET_SOCKET Socket
  1381. );
  1382. /*++
  1383. Routine Description:
  1384. This routine adds a bound socket to the list of listening sockets,
  1385. officially allowing clients to attempt to connect to it.
  1386. Arguments:
  1387. Socket - Supplies a pointer to the socket to mark as listning.
  1388. Return Value:
  1389. Status code.
  1390. --*/
  1391. typedef
  1392. KSTATUS
  1393. (*PNET_NETWORK_CONNECT) (
  1394. PNET_SOCKET Socket,
  1395. PNETWORK_ADDRESS Address
  1396. );
  1397. /*++
  1398. Routine Description:
  1399. This routine connects the given socket to a specific remote address. It
  1400. will implicitly bind the socket if it is not yet locally bound.
  1401. Arguments:
  1402. Socket - Supplies a pointer to the socket to use for the connection.
  1403. Address - Supplies a pointer to the remote address to bind this socket to.
  1404. Return Value:
  1405. Status code.
  1406. --*/
  1407. typedef
  1408. KSTATUS
  1409. (*PNET_NETWORK_DISCONNECT) (
  1410. PNET_SOCKET Socket
  1411. );
  1412. /*++
  1413. Routine Description:
  1414. This routine will disconnect the given socket from its remote address.
  1415. Arguments:
  1416. Socket - Supplies a pointer to the socket to disconnect.
  1417. Return Value:
  1418. Status code.
  1419. --*/
  1420. typedef
  1421. KSTATUS
  1422. (*PNET_NETWORK_CLOSE) (
  1423. PNET_SOCKET Socket
  1424. );
  1425. /*++
  1426. Routine Description:
  1427. This routine closes a socket connection.
  1428. Arguments:
  1429. Socket - Supplies a pointer to the socket to shut down.
  1430. Return Value:
  1431. Status code.
  1432. --*/
  1433. typedef
  1434. KSTATUS
  1435. (*PNET_NETWORK_SEND) (
  1436. PNET_SOCKET Socket,
  1437. PNETWORK_ADDRESS Destination,
  1438. PNET_SOCKET_LINK_OVERRIDE LinkOverride,
  1439. PNET_PACKET_LIST PacketList
  1440. );
  1441. /*++
  1442. Routine Description:
  1443. This routine sends data through the network.
  1444. Arguments:
  1445. Socket - Supplies a pointer to the socket to send the data to.
  1446. Destination - Supplies a pointer to the network address to send to.
  1447. LinkOverride - Supplies an optional pointer to a structure that contains
  1448. all the necessary information to send data out a link on behalf
  1449. of the given socket.
  1450. PacketList - Supplies a pointer to a list of network packets to send. Data
  1451. in these packets may be modified by this routine, but must not be used
  1452. once this routine returns.
  1453. Return Value:
  1454. Status code. It is assumed that either all packets are submitted (if
  1455. success is returned) or none of the packets were submitted (if a failing
  1456. status is returned).
  1457. --*/
  1458. typedef
  1459. VOID
  1460. (*PNET_NETWORK_PROCESS_RECEIVED_DATA) (
  1461. PNET_RECEIVE_CONTEXT ReceiveContext
  1462. );
  1463. /*++
  1464. Routine Description:
  1465. This routine is called to process a received packet.
  1466. Arguments:
  1467. ReceiveContext - Supplies a pointer to the receive context that stores the
  1468. link and packet information.
  1469. Return Value:
  1470. None. When the function returns, the memory associated with the packet may
  1471. be reclaimed and reused.
  1472. --*/
  1473. typedef
  1474. ULONG
  1475. (*PNET_NETWORK_PRINT_ADDRESS) (
  1476. PNETWORK_ADDRESS Address,
  1477. PSTR Buffer,
  1478. ULONG BufferLength
  1479. );
  1480. /*++
  1481. Routine Description:
  1482. This routine is called to convert a network address into a string, or
  1483. determine the length of the buffer needed to convert an address into a
  1484. string.
  1485. Arguments:
  1486. Address - Supplies an optional pointer to a network address to convert to
  1487. a string.
  1488. Buffer - Supplies an optional pointer where the string representation of
  1489. the address will be returned.
  1490. BufferLength - Supplies the length of the supplied buffer, in bytes.
  1491. Return Value:
  1492. Returns the maximum length of any address if no network address is
  1493. supplied.
  1494. Returns the actual length of the network address string if a network address
  1495. was supplied, including the null terminator.
  1496. --*/
  1497. typedef
  1498. KSTATUS
  1499. (*PNET_NETWORK_GET_SET_INFORMATION) (
  1500. PNET_SOCKET Socket,
  1501. SOCKET_INFORMATION_TYPE InformationType,
  1502. UINTN Option,
  1503. PVOID Data,
  1504. PUINTN DataSize,
  1505. BOOL Set
  1506. );
  1507. /*++
  1508. Routine Description:
  1509. This routine gets or sets properties of the given socket.
  1510. Arguments:
  1511. Socket - Supplies a pointer to the socket to get or set information for.
  1512. InformationType - Supplies the socket information type category to which
  1513. specified option belongs.
  1514. Option - Supplies the option to get or set, which is specific to the
  1515. information type. The type of this value is generally
  1516. SOCKET_<information_type>_OPTION.
  1517. Data - Supplies a pointer to the data buffer where the data is either
  1518. returned for a get operation or given for a set operation.
  1519. DataSize - Supplies a pointer that on input constains the size of the data
  1520. buffer. On output, this contains the required size of the data buffer.
  1521. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  1522. a set operation (TRUE).
  1523. Return Value:
  1524. STATUS_SUCCESS on success.
  1525. STATUS_INVALID_PARAMETER if the information type is incorrect.
  1526. STATUS_BUFFER_TOO_SMALL if the data buffer is too small to receive the
  1527. requested option.
  1528. STATUS_NOT_SUPPORTED_BY_PROTOCOL if the socket option is not supported by
  1529. the socket.
  1530. --*/
  1531. typedef
  1532. NET_ADDRESS_TYPE
  1533. (*PNET_NETWORK_GET_ADDRESS_TYPE) (
  1534. PNET_LINK Link,
  1535. PNET_LINK_ADDRESS_ENTRY LinkAddressEntry,
  1536. PNETWORK_ADDRESS Address
  1537. );
  1538. /*++
  1539. Routine Description:
  1540. This routine gets the type of the given address, categorizing it as unicast,
  1541. broadcast, or multicast.
  1542. Arguments:
  1543. Link - Supplies an optional pointer to the network link to which the
  1544. address is bound.
  1545. LinkAddressEntry - Supplies an optional pointer to a network link address
  1546. entry to use while classifying the address.
  1547. Address - Supplies a pointer to the network address to categorize.
  1548. Return Value:
  1549. Returns the type of the specified address.
  1550. --*/
  1551. typedef
  1552. ULONG
  1553. (*PNET_NETWORK_CHECKSUM_PSEUDO_HEADER) (
  1554. PNETWORK_ADDRESS Source,
  1555. PNETWORK_ADDRESS Destination,
  1556. ULONG PacketLength,
  1557. UCHAR Protocol
  1558. );
  1559. /*++
  1560. Routine Description:
  1561. This routine computes the network's pseudo-header checksum as the one's
  1562. complement sum of all 32-bit words in the header. The pseudo-header is
  1563. folded into a 16-bit checksum by the caller.
  1564. Arguments:
  1565. Source - Supplies a pointer to the source address.
  1566. Destination - Supplies a pointer to the destination address.
  1567. PacketLength - Supplies the packet length to include in the pseudo-header.
  1568. Protocol - Supplies the protocol value used in the pseudo header.
  1569. Return Value:
  1570. Returns the checksum of the pseudo-header.
  1571. --*/
  1572. typedef
  1573. KSTATUS
  1574. (*PNET_NETWORK_CONFIGURE_LINK_ADDRESS) (
  1575. PNET_LINK Link,
  1576. PNET_LINK_ADDRESS_ENTRY LinkAddress,
  1577. BOOL Configure
  1578. );
  1579. /*++
  1580. Routine Description:
  1581. This routine configures or dismantles the given link address for use over
  1582. the network on the given link.
  1583. Arguments:
  1584. Link - Supplies a pointer to the link to which the address entry belongs.
  1585. LinkAddress - Supplies a pointer to the link address entry to configure.
  1586. Configure - Supplies a boolean indicating whether or not the link address
  1587. should be configured for use (TRUE) or taken out of service (FALSE).
  1588. Return Value:
  1589. Status code.
  1590. --*/
  1591. typedef
  1592. KSTATUS
  1593. (*PNET_NETWORK_JOIN_LEAVE_MULTICAST_GROUP) (
  1594. PNET_NETWORK_MULTICAST_REQUEST Request,
  1595. BOOL Join
  1596. );
  1597. /*++
  1598. Routine Description:
  1599. This routine joins or leaves a multicast group using a network-specific
  1600. protocol.
  1601. Arguments:
  1602. Request - Supplies a pointer to the multicast group join/leave request.
  1603. Join - Supplies a boolean indicating whether to join (TRUE) or leave
  1604. (FALSE) the multicast group.
  1605. Return Value:
  1606. Status code.
  1607. --*/
  1608. /*++
  1609. Structure Description:
  1610. This structure defines interface between the core networking library and
  1611. a network.
  1612. Members:
  1613. InitializeLink - Stores a pointer to a function called when a new link
  1614. is created.
  1615. DestroyLink - Stores a pointer to a function called before a link is
  1616. destroyed.
  1617. InitializeSocket - Stores a pointer to a function that initializes a newly
  1618. created socket.
  1619. DestroySocket - Stores a pointer to a function that destroys network
  1620. specific socket structures allocated during initialize. This function
  1621. is optional if the initialize routine made no allocations.
  1622. BindToAddress - Stores a pointer to a function that binds an open but
  1623. unbound socket to a particular network address.
  1624. Listen - Stores a pointer to a function that marks the packet as listening
  1625. and allows clients to attempt to connect to it.
  1626. Connect - Stores a pointer to a function that binds a socket to a remote
  1627. host.
  1628. Close - Stores a pointer to a function used to shut down a connection.
  1629. Send - Stores a pointer to a function used to send data.
  1630. ProcessReceivedData - Stores a pointer to a function called when a
  1631. received packet comes in.
  1632. PrintAddress - Stores a pointer to a function used to convert a network
  1633. address into a string representation.
  1634. GetSetInformation - Stores a pointer to a function used to get or set
  1635. socket information.
  1636. CopyInformation - Stores a pointer to a function used to copy socket option
  1637. information from one socket to another. This function is optional if
  1638. there are no network specific socket options.
  1639. GetAddressType - Stores a pointer to a function used to categorize a given
  1640. network address into one of many types (e.g. unicast, broadcast,
  1641. mulitcast). This function is optional if unicast is the only supported
  1642. address type.
  1643. ChecksumPseudoHeader - Stores a pointer to a function used to compute the
  1644. one's complement sum of all 32-bit values in the network's
  1645. pseudo-header that is prepended to protocol checksums (e.g. TCP, UDP).
  1646. ConfigureLinkAddress - Stores a pointer to a function used to configure a
  1647. link address entry for use on this network. This involves invoking a
  1648. network-specific protocol to validate or assign an address for the link
  1649. address entry (e.g. DHCP, NDP, DHCPv6).
  1650. JoinLeaveMulticastGroup - Stores a pointer to a function used to join
  1651. or leave a multicast group using a network-specific protocol (e.g.
  1652. IGMP, MLD).
  1653. --*/
  1654. typedef struct _NET_NETWORK_INTERFACE {
  1655. PNET_NETWORK_INITIALIZE_LINK InitializeLink;
  1656. PNET_NETWORK_DESTROY_LINK DestroyLink;
  1657. PNET_NETWORK_INITIALIZE_SOCKET InitializeSocket;
  1658. PNET_NETWORK_DESTROY_SOCKET DestroySocket;
  1659. PNET_NETWORK_BIND_TO_ADDRESS BindToAddress;
  1660. PNET_NETWORK_LISTEN Listen;
  1661. PNET_NETWORK_CONNECT Connect;
  1662. PNET_NETWORK_DISCONNECT Disconnect;
  1663. PNET_NETWORK_CLOSE Close;
  1664. PNET_NETWORK_SEND Send;
  1665. PNET_NETWORK_PROCESS_RECEIVED_DATA ProcessReceivedData;
  1666. PNET_NETWORK_PRINT_ADDRESS PrintAddress;
  1667. PNET_NETWORK_GET_SET_INFORMATION GetSetInformation;
  1668. PNET_NETWORK_GET_ADDRESS_TYPE GetAddressType;
  1669. PNET_NETWORK_CHECKSUM_PSEUDO_HEADER ChecksumPseudoHeader;
  1670. PNET_NETWORK_CONFIGURE_LINK_ADDRESS ConfigureLinkAddress;
  1671. PNET_NETWORK_JOIN_LEAVE_MULTICAST_GROUP JoinLeaveMulticastGroup;
  1672. } NET_NETWORK_INTERFACE, *PNET_NETWORK_INTERFACE;
  1673. /*++
  1674. Structure Description:
  1675. This structure defines a network entry.
  1676. Members:
  1677. ListEntry - Stores pointers to the next and previous network entries, used
  1678. internally by the core networking library.
  1679. Domain - Stores the domain this network implements.
  1680. ParentProtocolNumber - Stores the protocol number in the parent layer's
  1681. protocol.
  1682. Interface - Stores the interface presented to the core networking library
  1683. for this network.
  1684. --*/
  1685. struct _NET_NETWORK_ENTRY {
  1686. LIST_ENTRY ListEntry;
  1687. NET_DOMAIN_TYPE Domain;
  1688. ULONG ParentProtocolNumber;
  1689. NET_NETWORK_INTERFACE Interface;
  1690. };
  1691. /*++
  1692. Structure Description:
  1693. This structure defines the context for receiving a network packet. Each
  1694. layer will fill in the portions of the context it owns and pass it up the
  1695. stack. This structure and even the address pointers can be stack allocated
  1696. as it will not be referenced after the network layers have completed the
  1697. receive.
  1698. Members:
  1699. Packet - Supplies a pointer to the packet that came in over the network.
  1700. This structure may not be used as a scratch space while the packet
  1701. travels up the stack as it may be sent out to multiple sockets (e.g.
  1702. multicast or broadcast packets).
  1703. Link - Supplies a pointer to the network link that received the packet.
  1704. Network - Supplies a pointer to the network to which the packet belongs.
  1705. Protocol - Supplies a pointer to the protocol to which the packet belongs.
  1706. Source - Supplies a pointer to the source (remote) address of the packet.
  1707. Destination - Supplies a pointer to the destination (local) address of the
  1708. packet.
  1709. ParentProtocolNumber - Stores the protocol number in the parent layer's
  1710. protocol. This will always be set after the network layer executes.
  1711. --*/
  1712. struct _NET_RECEIVE_CONTEXT {
  1713. PNET_PACKET_BUFFER Packet;
  1714. PNET_LINK Link;
  1715. PNET_NETWORK_ENTRY Network;
  1716. PNET_PROTOCOL_ENTRY Protocol;
  1717. PNETWORK_ADDRESS Source;
  1718. PNETWORK_ADDRESS Destination;
  1719. ULONG ParentProtocolNumber;
  1720. };
  1721. //
  1722. // -------------------------------------------------------------------- Globals
  1723. //
  1724. //
  1725. // -------------------------------------------------------- Function Prototypes
  1726. //
  1727. NET_API
  1728. KSTATUS
  1729. NetRegisterProtocol (
  1730. PNET_PROTOCOL_ENTRY NewProtocol,
  1731. PHANDLE ProtocolHandle
  1732. );
  1733. /*++
  1734. Routine Description:
  1735. This routine registers a new protocol type with the core networking
  1736. library.
  1737. Arguments:
  1738. NewProtocol - Supplies a pointer to the protocol information. The core
  1739. networking library *will* continue to use the memory after the function
  1740. returns, so this pointer had better not point to stack allocated
  1741. memory.
  1742. ProtocolHandle - Supplies an optional pointer that receives a handle to the
  1743. registered protocol on success.
  1744. Return Value:
  1745. STATUS_SUCCESS on success.
  1746. STATUS_INVALID_PARAMETER if part of the structure isn't filled out
  1747. correctly.
  1748. STATUS_DUPLICATE_ENTRY if the socket type is already registered.
  1749. --*/
  1750. NET_API
  1751. VOID
  1752. NetUnregisterProtocol (
  1753. HANDLE ProtocolHandle
  1754. );
  1755. /*++
  1756. Routine Description:
  1757. This routine unregisters the given protocol from the core networking
  1758. library.
  1759. Arguments:
  1760. ProtocolHandle - Supplies the handle to the protocol to unregister.
  1761. Return Value:
  1762. None.
  1763. --*/
  1764. NET_API
  1765. KSTATUS
  1766. NetRegisterNetworkLayer (
  1767. PNET_NETWORK_ENTRY NewNetworkEntry,
  1768. PHANDLE NetworkHandle
  1769. );
  1770. /*++
  1771. Routine Description:
  1772. This routine registers a new network type with the core networking library.
  1773. Arguments:
  1774. NewNetworkEntry - Supplies a pointer to the network information. The core
  1775. library will not reference this memory after the function returns, a
  1776. copy will be made.
  1777. NetworkHandle - Supplies an optional pointer that receives a handle to the
  1778. registered network layer on success.
  1779. Return Value:
  1780. STATUS_SUCCESS on success.
  1781. STATUS_INVALID_PARAMETER if part of the structure isn't filled out
  1782. correctly.
  1783. STATUS_INSUFFICIENT_RESOURCES if memory could not be allocated.
  1784. STATUS_DUPLICATE_ENTRY if the network type is already registered.
  1785. --*/
  1786. NET_API
  1787. VOID
  1788. NetUnregisterNetworkLayer (
  1789. HANDLE NetworkHandle
  1790. );
  1791. /*++
  1792. Routine Description:
  1793. This routine unregisters the given network layer from the core networking
  1794. library.
  1795. Arguments:
  1796. NetworkHandle - Supplies the handle to the network layer to unregister.
  1797. Return Value:
  1798. None.
  1799. --*/
  1800. NET_API
  1801. KSTATUS
  1802. NetRegisterDataLinkLayer (
  1803. PNET_DATA_LINK_ENTRY NewDataLinkEntry,
  1804. PHANDLE DataLinkHandle
  1805. );
  1806. /*++
  1807. Routine Description:
  1808. This routine registers a new data link type with the core networking
  1809. library.
  1810. Arguments:
  1811. NewDataLinkEntry - Supplies a pointer to the link information. The core
  1812. library will not reference this memory after the function returns, a
  1813. copy will be made.
  1814. DataLinkHandle - Supplies an optional pointer that receives a handle to the
  1815. registered data link layer on success.
  1816. Return Value:
  1817. STATUS_SUCCESS on success.
  1818. STATUS_INVALID_PARAMETER if part of the structure isn't filled out
  1819. correctly.
  1820. STATUS_INSUFFICIENT_RESOURCES if memory could not be allocated.
  1821. STATUS_DUPLICATE_ENTRY if the link type is already registered.
  1822. --*/
  1823. NET_API
  1824. VOID
  1825. NetUnregisterDataLinkLayer (
  1826. HANDLE DataLinkHandle
  1827. );
  1828. /*++
  1829. Routine Description:
  1830. This routine unregisters the given data link layer from the core networking
  1831. library.
  1832. Arguments:
  1833. DataLinkHandle - Supplies the handle to the data link layer to unregister.
  1834. Return Value:
  1835. None.
  1836. --*/
  1837. NET_API
  1838. PNET_NETWORK_ENTRY
  1839. NetGetNetworkEntry (
  1840. ULONG ParentProtocolNumber
  1841. );
  1842. /*++
  1843. Routine Description:
  1844. This routine looks up a registered network layer given the parent protocol
  1845. number.
  1846. Arguments:
  1847. ParentProtocolNumber - Supplies the parent protocol number of the desired
  1848. network layer.
  1849. Return Value:
  1850. Returns a pointer to the network layer entry on success.
  1851. --*/
  1852. NET_API
  1853. PNET_PROTOCOL_ENTRY
  1854. NetGetProtocolEntry (
  1855. ULONG ParentProtocolNumber
  1856. );
  1857. /*++
  1858. Routine Description:
  1859. This routine looks up a registered protocol layer given the parent protocol
  1860. number.
  1861. Arguments:
  1862. ParentProtocolNumber - Supplies the parent protocol number of the desired
  1863. protocol layer.
  1864. Return Value:
  1865. Returns a pointer to the protocol layer entry on success.
  1866. --*/
  1867. NET_API
  1868. VOID
  1869. NetProcessReceivedPacket (
  1870. PNET_LINK Link,
  1871. PNET_PACKET_BUFFER Packet
  1872. );
  1873. /*++
  1874. Routine Description:
  1875. This routine is called by the low level NIC driver to pass received packets
  1876. onto the core networking library for dispatching.
  1877. Arguments:
  1878. Link - Supplies a pointer to the link that received the packet.
  1879. Packet - Supplies a pointer to a structure describing the incoming packet.
  1880. This structure may be used as a scratch space while this routine
  1881. executes and the packet travels up the stack, but will not be accessed
  1882. after this routine returns.
  1883. Return Value:
  1884. None. When the function returns, the memory associated with the packet may
  1885. be reclaimed and reused.
  1886. --*/
  1887. NET_API
  1888. BOOL
  1889. NetGetGlobalDebugFlag (
  1890. VOID
  1891. );
  1892. /*++
  1893. Routine Description:
  1894. This routine returns the current value of the global networking debug flag.
  1895. Arguments:
  1896. None.
  1897. Return Value:
  1898. TRUE if debug information should be collected throughout the networking
  1899. subsystem.
  1900. FALSE if verbose debug information should be suppressed globally.
  1901. --*/
  1902. NET_API
  1903. VOID
  1904. NetDebugPrintAddress (
  1905. PNETWORK_ADDRESS Address
  1906. );
  1907. /*++
  1908. Routine Description:
  1909. This routine prints the given address to the debug console.
  1910. Arguments:
  1911. Address - Supplies a pointer to the address to print.
  1912. Return Value:
  1913. None.
  1914. --*/
  1915. NET_API
  1916. KSTATUS
  1917. NetAddLink (
  1918. PNET_LINK_PROPERTIES Properties,
  1919. PNET_LINK *NewLink
  1920. );
  1921. /*++
  1922. Routine Description:
  1923. This routine adds a new network link based on the given properties. The
  1924. link must be ready to send and receive traffic and have a valid physical
  1925. layer address supplied in the properties.
  1926. Arguments:
  1927. Properties - Supplies a pointer describing the properties and interface of
  1928. the link. This memory will not be referenced after the function returns,
  1929. so this may be a stack allocated structure.
  1930. NewLink - Supplies a pointer where a pointer to the new link will be
  1931. returned on success.
  1932. Return Value:
  1933. STATUS_SUCCESS on success.
  1934. STATUS_INSUFFICIENT_RESOURCES if memory could not be allocated for the
  1935. structure.
  1936. --*/
  1937. NET_API
  1938. VOID
  1939. NetLinkAddReference (
  1940. PNET_LINK Link
  1941. );
  1942. /*++
  1943. Routine Description:
  1944. This routine increases the reference count on a network link.
  1945. Arguments:
  1946. Link - Supplies a pointer to the network link whose reference count
  1947. should be incremented.
  1948. Return Value:
  1949. None.
  1950. --*/
  1951. NET_API
  1952. VOID
  1953. NetLinkReleaseReference (
  1954. PNET_LINK Link
  1955. );
  1956. /*++
  1957. Routine Description:
  1958. This routine decreases the reference count of a network link, and destroys
  1959. the link if the reference count drops to zero.
  1960. Arguments:
  1961. Link - Supplies a pointer to the network link whose reference count
  1962. should be decremented.
  1963. Return Value:
  1964. None.
  1965. --*/
  1966. NET_API
  1967. VOID
  1968. NetSetLinkState (
  1969. PNET_LINK Link,
  1970. BOOL LinkUp,
  1971. ULONGLONG LinkSpeed
  1972. );
  1973. /*++
  1974. Routine Description:
  1975. This routine sets the link state of the given link. The physical device
  1976. layer is responsible for synchronizing link state changes.
  1977. Arguments:
  1978. Link - Supplies a pointer to the link whose state is changing.
  1979. LinkUp - Supplies a boolean indicating whether the link is active (TRUE) or
  1980. disconnected (FALSE).
  1981. LinkSpeed - Supplies the speed of the link, in bits per second.
  1982. Return Value:
  1983. None.
  1984. --*/
  1985. NET_API
  1986. VOID
  1987. NetGetLinkState (
  1988. PNET_LINK Link,
  1989. PBOOL LinkUp,
  1990. PULONGLONG LinkSpeed
  1991. );
  1992. /*++
  1993. Routine Description:
  1994. This routine gets the link state of the given link.
  1995. Arguments:
  1996. Link - Supplies a pointer to the link whose state is being retrieved.
  1997. LinkUp - Supplies a pointer that receives a boolean indicating whether the
  1998. link is active (TRUE) or disconnected (FALSE). This parameter is
  1999. optional.
  2000. LinkSpeed - Supplies a pointer that receives the speed of the link, in bits
  2001. per second. This parameter is optional.
  2002. Return Value:
  2003. None.
  2004. --*/
  2005. NET_API
  2006. KSTATUS
  2007. NetGetSetLinkDeviceInformation (
  2008. PNET_LINK Link,
  2009. PUUID Uuid,
  2010. PVOID Data,
  2011. PUINTN DataSize,
  2012. BOOL Set
  2013. );
  2014. /*++
  2015. Routine Description:
  2016. This routine gets or sets device information for a link.
  2017. Arguments:
  2018. Link - Supplies a pointer to the link whose device information is being
  2019. retrieved or set.
  2020. Uuid - Supplies a pointer to the information identifier.
  2021. Data - Supplies a pointer to the data buffer.
  2022. DataSize - Supplies a pointer that on input contains the size of the data
  2023. buffer in bytes. On output, returns the needed size of the data buffer,
  2024. even if the supplied buffer was nonexistant or too small.
  2025. Set - Supplies a boolean indicating whether to get the information (FALSE)
  2026. or set the information (TRUE).
  2027. Return Value:
  2028. STATUS_SUCCESS on success.
  2029. STATUS_BUFFER_TOO_SMALL if the supplied buffer was too small.
  2030. STATUS_NOT_HANDLED if the given UUID was not recognized.
  2031. --*/
  2032. NET_API
  2033. VOID
  2034. NetRemoveLink (
  2035. PNET_LINK Link
  2036. );
  2037. /*++
  2038. Routine Description:
  2039. This routine removes a link from the networking core after its device has
  2040. been removed. This should not be used if the media has simply been removed.
  2041. In that case, setting the link state to 'down' is suffiient. There may
  2042. still be outstanding references on the link, so the networking core will
  2043. call the device back to notify it when the link is destroyed.
  2044. Arguments:
  2045. Link - Supplies a pointer to the link to remove.
  2046. Return Value:
  2047. None.
  2048. --*/
  2049. NET_API
  2050. KSTATUS
  2051. NetFindLinkForLocalAddress (
  2052. PNETWORK_ADDRESS LocalAddress,
  2053. PNET_LINK Link,
  2054. PNET_LINK_LOCAL_ADDRESS LinkResult
  2055. );
  2056. /*++
  2057. Routine Description:
  2058. This routine searches for a link and the associated address entry that
  2059. matches the given local address. If a link is supplied as a hint, then the
  2060. given link must be able to service the given address for this routine to
  2061. succeed.
  2062. Arguments:
  2063. LocalAddress - Supplies a pointer to the local address to test against.
  2064. Link - Supplies an optional pointer to a link that the local address must
  2065. be from.
  2066. LinkResult - Supplies a pointer that receives the found link, link address
  2067. entry, and local address.
  2068. Return Value:
  2069. STATUS_SUCCESS if a link was found and bound with the socket.
  2070. STATUS_INVALID_ADDRESS if no link was found to own that address.
  2071. STATUS_NO_NETWORK_CONNECTION if no networks are available.
  2072. --*/
  2073. NET_API
  2074. KSTATUS
  2075. NetFindLinkForRemoteAddress (
  2076. PNETWORK_ADDRESS RemoteAddress,
  2077. PNET_LINK_LOCAL_ADDRESS LinkResult
  2078. );
  2079. /*++
  2080. Routine Description:
  2081. This routine searches for a link and associated address entry that can
  2082. reach the given remote address.
  2083. Arguments:
  2084. RemoteAddress - Supplies a pointer to the address to test against.
  2085. LinkResult - Supplies a pointer that receives the link information,
  2086. including the link, link address entry, and associated local address.
  2087. Return Value:
  2088. STATUS_SUCCESS if a link was found and bound with the socket.
  2089. STATUS_NO_NETWORK_CONNECTION if no networks are available.
  2090. --*/
  2091. NET_API
  2092. KSTATUS
  2093. NetLookupLinkByDevice (
  2094. PDEVICE Device,
  2095. PNET_LINK *Link
  2096. );
  2097. /*++
  2098. Routine Description:
  2099. This routine looks for a link that belongs to the given device. If a link
  2100. is found, a reference will be added. It is the callers responsibility to
  2101. release this reference.
  2102. Arguments:
  2103. Device - Supplies a pointer to the device for which the link is being
  2104. searched.
  2105. Link - Supplies a pointer that receives a pointer to the link, if found.
  2106. Return Value:
  2107. Status code.
  2108. --*/
  2109. NET_API
  2110. KSTATUS
  2111. NetCreateLinkAddressEntry (
  2112. PNET_LINK Link,
  2113. PNETWORK_ADDRESS Address,
  2114. PNETWORK_ADDRESS Subnet,
  2115. PNETWORK_ADDRESS DefaultGateway,
  2116. BOOL StaticAddress,
  2117. PNET_LINK_ADDRESS_ENTRY *NewLinkAddress
  2118. );
  2119. /*++
  2120. Routine Description:
  2121. This routine initializes a new network link address entry.
  2122. Arguments:
  2123. Link - Supplies a pointer to the physical link that has the new network
  2124. address.
  2125. Address - Supplies a pointer to the address to assign to the link address
  2126. entry. At least the network domain needs to be filled in.
  2127. Subnet - Supplies an optional pointer to the subnet mask to assign to the
  2128. link address entry.
  2129. DefaultGateway - Supplies an optional pointer to the default gateway
  2130. address to assign to the link address entry.
  2131. StaticAddress - Supplies a boolean indicating if the provided information
  2132. is a static configuration of the link address entry. This parameter is
  2133. only used when the Address, Subnet, and DefaultGateway parameters are
  2134. supplied.
  2135. NewLinkAddress - Supplies a pointer where a pointer to the new link address
  2136. will be returned. The new link address will also be inserted onto the
  2137. link.
  2138. Return Value:
  2139. Status code.
  2140. --*/
  2141. NET_API
  2142. VOID
  2143. NetDestroyLinkAddressEntry (
  2144. PNET_LINK Link,
  2145. PNET_LINK_ADDRESS_ENTRY LinkAddress
  2146. );
  2147. /*++
  2148. Routine Description:
  2149. This routine removes and destroys a link address.
  2150. Arguments:
  2151. Link - Supplies a pointer to the physical link that has the network address.
  2152. LinkAddress - Supplies a pointer to the link address to remove and destroy.
  2153. Return Value:
  2154. None.
  2155. --*/
  2156. NET_API
  2157. PNET_TRANSLATION_ENTRY
  2158. NetLookupAddressTranslation (
  2159. PNET_LINK Link,
  2160. PNETWORK_ADDRESS NetworkAddress
  2161. );
  2162. /*++
  2163. Routine Description:
  2164. This routine performs a lookup for an address translation entry given the
  2165. network address. The caller is responsible for releasing the reference
  2166. taken on success.
  2167. Arguments:
  2168. Link - Supplies a pointer to the link that supposedly owns the network
  2169. address.
  2170. NetworkAddress - Supplies a pointer to the network address to look up.
  2171. Return Value:
  2172. Returns a pointer to a translation entry on success, or NULL on failure.
  2173. --*/
  2174. NET_API
  2175. KSTATUS
  2176. NetAddAddressTranslation (
  2177. PNET_LINK Link,
  2178. PNETWORK_ADDRESS NetworkAddress,
  2179. PNETWORK_ADDRESS PhysicalAddress
  2180. );
  2181. /*++
  2182. Routine Description:
  2183. This routine adds a mapping between a network address and its associated
  2184. physical address.
  2185. Arguments:
  2186. Link - Supplies a pointer to the link receiving the mapping.
  2187. NetworkAddress - Supplies a pointer to the network address whose physical
  2188. mapping is known.
  2189. PhysicalAddress - Supplies a pointer to the physical address corresponding
  2190. to the network address.
  2191. Return Value:
  2192. Status code.
  2193. --*/
  2194. NET_API
  2195. KSTATUS
  2196. NetRemoveAddressTranslation (
  2197. PNET_LINK Link,
  2198. PNETWORK_ADDRESS NetworkAddress
  2199. );
  2200. /*++
  2201. Routine Description:
  2202. This routine attempts to remove an network address translation from the
  2203. link's translation cache.
  2204. Arguments:
  2205. Link - Supplies a pointer to the link that supposedly owns the network
  2206. address.
  2207. NetworkAddress - Supplies a pointer to the network address whose
  2208. translation is to be removed.
  2209. Return Value:
  2210. Status code.
  2211. --*/
  2212. NET_API
  2213. VOID
  2214. NetTranslationEntryAddReference (
  2215. PNET_TRANSLATION_ENTRY TranslationEntry
  2216. );
  2217. /*++
  2218. Routine Description:
  2219. This routine adds a reference to the given address translation entry.
  2220. Arguments:
  2221. TranslationEntry - Supplies a pointer to an address translation entry.
  2222. Return Value:
  2223. None.
  2224. --*/
  2225. NET_API
  2226. VOID
  2227. NetTranslationEntryReleaseReference (
  2228. PNET_TRANSLATION_ENTRY TranslationEntry
  2229. );
  2230. /*++
  2231. Routine Description:
  2232. This routine release a reference on the given address translation entry.
  2233. Arguments:
  2234. TranslationEntry - Supplies a pointer to an address translation entry.
  2235. Return Value:
  2236. None.
  2237. --*/
  2238. NET_API
  2239. KSTATUS
  2240. NetFindEntryForAddress (
  2241. PNET_LINK Link,
  2242. PNETWORK_ADDRESS Address,
  2243. PNET_LINK_ADDRESS_ENTRY *AddressEntry
  2244. );
  2245. /*++
  2246. Routine Description:
  2247. This routine searches for a link address entry within the given link
  2248. matching the desired address.
  2249. Arguments:
  2250. Link - Supplies the link whose address entries should be searched.
  2251. Address - Supplies the address to search for.
  2252. AddressEntry - Supplies a pointer where the address entry will be returned
  2253. on success.
  2254. Return Value:
  2255. STATUS_SUCCESS if a link was found and bound with the socket.
  2256. STATUS_INVALID_ADDRESS if no link was found to own that address.
  2257. --*/
  2258. NET_API
  2259. KSTATUS
  2260. NetActivateSocket (
  2261. PNET_SOCKET Socket
  2262. );
  2263. /*++
  2264. Routine Description:
  2265. This routine activates or re-activates a socket, making it eligible to
  2266. receive data or updating it from an unbound or locally bound socket to a
  2267. fully bound socket.
  2268. Arguments:
  2269. Socket - Supplies a pointer to the initialized socket to add to the
  2270. listening sockets tree.
  2271. Return Value:
  2272. Status code.
  2273. --*/
  2274. NET_API
  2275. VOID
  2276. NetDeactivateSocket (
  2277. PNET_SOCKET Socket
  2278. );
  2279. /*++
  2280. Routine Description:
  2281. This routine removes a socket from the socket tree it's on, removing it
  2282. from eligibility to receive packets. If the socket is removed from the
  2283. tree then a reference will be released.
  2284. Arguments:
  2285. Socket - Supplies a pointer to the initialized socket to remove from the
  2286. socket tree.
  2287. Return Value:
  2288. None.
  2289. --*/
  2290. NET_API
  2291. KSTATUS
  2292. NetBindSocket (
  2293. PNET_SOCKET Socket,
  2294. NET_SOCKET_BINDING_TYPE TreeType,
  2295. PNET_LINK_LOCAL_ADDRESS LocalInformation,
  2296. PNETWORK_ADDRESS RemoteAddress,
  2297. ULONG Flags
  2298. );
  2299. /*++
  2300. Routine Description:
  2301. This routine officially binds a socket to a local address, local port,
  2302. remote address and remote port tuple by adding it to the appropriate socket
  2303. tree. It can also re-bind a socket in the case where it has already been
  2304. bound to a different tree.
  2305. Arguments:
  2306. Socket - Supplies a pointer to the initialized socket to bind.
  2307. TreeType - Supplies the type of tree to add the socket to.
  2308. LocalInformation - Supplies an optional pointer to the information for the
  2309. local link or address to which the socket shall be bound. Use this for
  2310. unbound sockets, leaving the link and link address NULL.
  2311. RemoteAddress - Supplies an optional pointer to a remote address to use
  2312. when fully binding the socket.
  2313. Flags - Supplies a bitmask of binding flags. See NET_SOCKET_BINDING_FLAG_*
  2314. for definitions.
  2315. Return Value:
  2316. Status code.
  2317. --*/
  2318. NET_API
  2319. KSTATUS
  2320. NetDisconnectSocket (
  2321. PNET_SOCKET Socket
  2322. );
  2323. /*++
  2324. Routine Description:
  2325. This routine disconnects a socket from the fully bound state, rolling it
  2326. back to the locally bound state.
  2327. Arguments:
  2328. Socket - Supplies a pointer to the socket to disconnect.
  2329. Return Value:
  2330. Status code.
  2331. --*/
  2332. NET_API
  2333. VOID
  2334. NetInitializeSocketLinkOverride (
  2335. PNET_SOCKET Socket,
  2336. PNET_LINK_LOCAL_ADDRESS LinkInformation,
  2337. PNET_SOCKET_LINK_OVERRIDE LinkOverride
  2338. );
  2339. /*++
  2340. Routine Description:
  2341. This routine initializes the given socket link override structure with the
  2342. appropriate mix of socket and link information.
  2343. Arguments:
  2344. Socket - Supplies a pointer to a network socket.
  2345. LinkInformation - Supplies a pointer to link local address information.
  2346. LinkOverride - Supplies a pointer to a socket link override structure that
  2347. will be filled in by this routine.
  2348. Return Value:
  2349. None.
  2350. --*/
  2351. NET_API
  2352. KSTATUS
  2353. NetFindSocket (
  2354. PNET_RECEIVE_CONTEXT ReceiveContext,
  2355. PNET_SOCKET *Socket
  2356. );
  2357. /*++
  2358. Routine Description:
  2359. This routine attempts to find a socket on the receiving end of the given
  2360. context based on matching the addresses and protocol. If the socket is
  2361. found and returned, the reference count will be increased on it. It is the
  2362. caller's responsiblity to release that reference. If this routine returns
  2363. that more processing is required, then subsequent calls should pass the
  2364. previously found socket back to the routine and the search will pick up
  2365. where it left off.
  2366. Arguments:
  2367. ReceiveContext - Supplies a pointer to the receive context used to find
  2368. the socket. This contains the remote address, local address, protocol,
  2369. and network to match on.
  2370. Socket - Supplies a pointer that receives a pointer to the found socket on
  2371. output. On input, it can optionally contain a pointer to the socket
  2372. from which the search for a new socket should start.
  2373. Return Value:
  2374. STATUS_SUCCESS if a socket was found.
  2375. STATUS_MORE_PROCESSING_REQUIRED if a socket was found, but more sockets
  2376. may match the given address tuple.
  2377. Error status code otherwise.
  2378. --*/
  2379. NET_API
  2380. KSTATUS
  2381. NetGetSetNetworkDeviceInformation (
  2382. PNET_LINK Link,
  2383. PNET_LINK_ADDRESS_ENTRY LinkAddressEntry,
  2384. PNETWORK_DEVICE_INFORMATION Information,
  2385. BOOL Set
  2386. );
  2387. /*++
  2388. Routine Description:
  2389. This routine gets or sets the network device information for a particular
  2390. link.
  2391. Arguments:
  2392. Link - Supplies a pointer to the link to work with.
  2393. LinkAddressEntry - Supplies an optional pointer to the specific address
  2394. entry to set. If NULL, a link address entry matching the network type
  2395. contained in the information will be found.
  2396. Information - Supplies a pointer that either receives the device
  2397. information, or contains the new information to set. For set operations,
  2398. the information buffer will contain the current settings on return.
  2399. Set - Supplies a boolean indicating if the information should be set or
  2400. returned.
  2401. Return Value:
  2402. Status code.
  2403. --*/
  2404. NET_API
  2405. COMPARISON_RESULT
  2406. NetCompareNetworkAddresses (
  2407. PNETWORK_ADDRESS FirstAddress,
  2408. PNETWORK_ADDRESS SecondAddress
  2409. );
  2410. /*++
  2411. Routine Description:
  2412. This routine compares two network addresses.
  2413. Arguments:
  2414. FirstAddress - Supplies a pointer to the left side of the comparison.
  2415. SecondAddress - Supplies a pointer to the second side of the comparison.
  2416. Return Value:
  2417. Same if the two nodes have the same value.
  2418. Ascending if the first node is less than the second node.
  2419. Descending if the second node is less than the first node.
  2420. --*/
  2421. NET_API
  2422. USHORT
  2423. NetChecksumData (
  2424. PVOID Data,
  2425. ULONG DataLength
  2426. );
  2427. /*++
  2428. Routine Description:
  2429. This routine computes the given data's checksum as the one's complement of
  2430. the one's complement sum of all 16-bit words in the data.
  2431. Arguments:
  2432. Data - Supplies a pointer to the beginning of the data to checksum.
  2433. DataLength - Supplies the length of the data to checksum.
  2434. Return Value:
  2435. Returns the checksum for the given data.
  2436. --*/
  2437. NET_API
  2438. USHORT
  2439. NetChecksumPseudoHeaderAndData (
  2440. PNET_NETWORK_ENTRY Network,
  2441. PVOID Data,
  2442. ULONG DataLength,
  2443. PNETWORK_ADDRESS SourceAddress,
  2444. PNETWORK_ADDRESS DestinationAddress,
  2445. UCHAR Protocol
  2446. );
  2447. /*++
  2448. Routine Description:
  2449. This routine computes the given data's checksum as the one's complement of
  2450. the one's complement sum of all 16-bit words in the data and a network
  2451. specific pseudo-header generated from the given addresses, protocol and
  2452. data length.
  2453. Arguments:
  2454. Network - Supplies a pointer to the network to which the data and addresses
  2455. belong.
  2456. Data - Supplies a pointer to the beginning of the data to checksum.
  2457. DataLength - Supplies the length of the data to checksum.
  2458. SourceAddress - Supplies a pointer to the source address of the data, used
  2459. to compute the pseudo-header.
  2460. DestinationAddress - Supplies a pointer to the destination address of the
  2461. data, used to compute the pseudo-header.
  2462. Protocol - Supplies a protocol value used in the pseudo-header.
  2463. Return Value:
  2464. Returns the checksum for the given data and generated pseudo-header.
  2465. --*/
  2466. NET_API
  2467. KSTATUS
  2468. NetAllocateBuffer (
  2469. ULONG HeaderSize,
  2470. ULONG Size,
  2471. ULONG FooterSize,
  2472. PNET_LINK Link,
  2473. ULONG Flags,
  2474. PNET_PACKET_BUFFER *NewBuffer
  2475. );
  2476. /*++
  2477. Routine Description:
  2478. This routine allocates a network buffer.
  2479. Arguments:
  2480. HeaderSize - Supplies the number of header bytes needed.
  2481. Size - Supplies the number of data bytes needed.
  2482. FooterSize - Supplies the number of footer bytes needed.
  2483. Link - Supplies a pointer to the link the buffer will be sent through. If
  2484. a link is provided, then the buffer will be backed by physically
  2485. contiguous pages for the link's hardware. If no link is provided, then
  2486. the buffer will not be backed by physically contiguous pages.
  2487. Flags - Supplies a bitmask of allocation flags. See
  2488. NET_ALLOCATE_BUFFER_FLAG_* for definitions.
  2489. NewBuffer - Supplies a pointer where a pointer to the new allocation will be
  2490. returned on success.
  2491. Return Value:
  2492. STATUS_SUCCESS on success.
  2493. STATUS_INVALID_PARAMETER if a zero length buffer was requested.
  2494. STATUS_INSUFFICIENT_RESOURCES if the buffer or any auxiliary structures
  2495. could not be allocated.
  2496. --*/
  2497. NET_API
  2498. VOID
  2499. NetFreeBuffer (
  2500. PNET_PACKET_BUFFER Buffer
  2501. );
  2502. /*++
  2503. Routine Description:
  2504. This routine frees a previously allocated network buffer.
  2505. Arguments:
  2506. Buffer - Supplies a pointer to the buffer returned by the allocation
  2507. routine.
  2508. Return Value:
  2509. None.
  2510. --*/
  2511. NET_API
  2512. VOID
  2513. NetDestroyBufferList (
  2514. PNET_PACKET_LIST BufferList
  2515. );
  2516. /*++
  2517. Routine Description:
  2518. This routine destroys a list of network packet buffers, releasing all of
  2519. its associated resources, not including the buffer list structure.
  2520. Arguments:
  2521. BufferList - Supplies a pointer to the buffer list to be destroyed.
  2522. Return Value:
  2523. None.
  2524. --*/
  2525. NET_API
  2526. KSTATUS
  2527. NetInitializeMulticastSocket (
  2528. PNET_SOCKET Socket
  2529. );
  2530. /*++
  2531. Routine Description:
  2532. This routine initializes a network socket's multicast information.
  2533. Arguments:
  2534. Socket - Supplies a pointer to the network socket to initialize.
  2535. Return Value:
  2536. Status code.
  2537. --*/
  2538. NET_API
  2539. VOID
  2540. NetDestroyMulticastSocket (
  2541. PNET_SOCKET Socket
  2542. );
  2543. /*++
  2544. Routine Description:
  2545. This routine destroys all the multicast state associated with the given
  2546. socket.
  2547. Arguments:
  2548. Socket - Supplies a pointer to the socket whose multicast state is to be
  2549. destroyed.
  2550. Return Value:
  2551. None.
  2552. --*/
  2553. NET_API
  2554. KSTATUS
  2555. NetJoinSocketMulticastGroup (
  2556. PNET_SOCKET Socket,
  2557. PNET_SOCKET_MULTICAST_REQUEST Request
  2558. );
  2559. /*++
  2560. Routine Description:
  2561. This routine adds the given socket to a multicast group.
  2562. Arguments:
  2563. Socket - Supplies a pointer to a socket.
  2564. Request - Supplies a pointer to the multicast join request. This stores
  2565. the address of the multicast group to join along with interface
  2566. information to indicate which link should join the group.
  2567. Return Value:
  2568. Status code.
  2569. --*/
  2570. NET_API
  2571. KSTATUS
  2572. NetLeaveSocketMulticastGroup (
  2573. PNET_SOCKET Socket,
  2574. PNET_SOCKET_MULTICAST_REQUEST Request
  2575. );
  2576. /*++
  2577. Routine Description:
  2578. This routine removes the given socket from a multicast group.
  2579. Arguments:
  2580. Socket - Supplies a pointer to a socket.
  2581. Request - Supplies a pointer to the multicast leave request. This stores
  2582. the multicast group address to leave and the address of the interface
  2583. on which the socket joined the group.
  2584. Return Value:
  2585. Status code.
  2586. --*/
  2587. NET_API
  2588. KSTATUS
  2589. NetSetSocketMulticastInterface (
  2590. PNET_SOCKET Socket,
  2591. PNET_SOCKET_MULTICAST_REQUEST Request
  2592. );
  2593. /*++
  2594. Routine Description:
  2595. This routine sets a socket's default multicast interface.
  2596. Arguments:
  2597. Socket - Supplies a pointer a socket.
  2598. Request - Supplies a pointer to the request which dictates the default
  2599. interface.
  2600. Return Value:
  2601. Status code.
  2602. --*/
  2603. NET_API
  2604. KSTATUS
  2605. NetGetSocketMulticastInterface (
  2606. PNET_SOCKET Socket,
  2607. PNET_SOCKET_MULTICAST_REQUEST Request
  2608. );
  2609. /*++
  2610. Routine Description:
  2611. This routine gets a socket's default multicast interface.
  2612. Arguments:
  2613. Socket - Supplies a pointer a socket.
  2614. Request - Supplies a pointer that receives the current interface.
  2615. Return Value:
  2616. Status code.
  2617. --*/
  2618. NET_API
  2619. KSTATUS
  2620. NetJoinLinkMulticastGroup (
  2621. PNET_LINK Link,
  2622. PNET_LINK_ADDRESS_ENTRY LinkAddress,
  2623. PNETWORK_ADDRESS MulticastAddress
  2624. );
  2625. /*++
  2626. Routine Description:
  2627. This routine joins the multicast group on a link. If this is the first
  2628. request to join the supplied multicast group on the link, then the hardware
  2629. is reprogrammed to include messages to the multicast group's physical layer
  2630. address and the network is invoked to announce the join via a
  2631. network-specific protocol.
  2632. Arguments:
  2633. Link - Supplies a pointer to the network link joining the multicast group.
  2634. LinkAddress - Supplies a pointer to the link address entry via which the
  2635. link will join the group.
  2636. MulticastAddress - Supplies a pointer to the multicast address of the group
  2637. to join.
  2638. Return Value:
  2639. Status code.
  2640. --*/
  2641. NET_API
  2642. KSTATUS
  2643. NetLeaveLinkMulticastGroup (
  2644. PNET_LINK Link,
  2645. PNET_LINK_ADDRESS_ENTRY LinkAddress,
  2646. PNETWORK_ADDRESS MulticastAddress
  2647. );
  2648. /*++
  2649. Routine Description:
  2650. This routine removes a link from a multicast. If this is the last request
  2651. to leave a multicast group on the link, then the hardware is reprogrammed
  2652. to filter out messages to the multicast group and a network-specific
  2653. protocol is invoked to announce the link is leaving the group.
  2654. Arguments:
  2655. Link - Supplies a pointer to the network link leaving the multicast group.
  2656. LinkAddress - Supplies a pointer to the link address entry via which the
  2657. link will leave the group.
  2658. MulticastAddress - Supplies a pointer to the multicast address of the group
  2659. to leave.
  2660. Return Value:
  2661. Status code.
  2662. --*/
  2663. NET_API
  2664. VOID
  2665. NetDestroyLinkMulticastGroups (
  2666. PNET_LINK Link
  2667. );
  2668. /*++
  2669. Routine Description:
  2670. This routine destroys the links remaining multicast groups. It is meant to
  2671. be called during link destruction and does not attempt to update the MAC
  2672. address filters or notify the network. The link should have no references.
  2673. Arguments:
  2674. Link - Supplies a pointer to the link whose multicast groups are being
  2675. destroyed.
  2676. Return Value:
  2677. None.
  2678. --*/
  2679. //
  2680. // Link-specific definitions.
  2681. //
  2682. NET_API
  2683. BOOL
  2684. NetIsEthernetAddressValid (
  2685. BYTE Address[ETHERNET_ADDRESS_SIZE]
  2686. );
  2687. /*++
  2688. Routine Description:
  2689. This routine determines if the given ethernet address is a valid individual
  2690. address or not. This routine returns FALSE for 00:00:00:00:00:00 and
  2691. FF:FF:FF:FF:FF:FF, and TRUE for everything else.
  2692. Arguments:
  2693. Address - Supplies the address to check.
  2694. Return Value:
  2695. TRUE if the ethernet address is a valid individual address.
  2696. FALSE if the address is not valid.
  2697. --*/
  2698. NET_API
  2699. VOID
  2700. NetCreateEthernetAddress (
  2701. BYTE Address[ETHERNET_ADDRESS_SIZE]
  2702. );
  2703. /*++
  2704. Routine Description:
  2705. This routine generates a random ethernet address.
  2706. Arguments:
  2707. Address - Supplies the array where the new address will be stored.
  2708. Return Value:
  2709. None.
  2710. --*/