Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ndp.c 34KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. /*
  2. * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <errno.h>
  24. #include <byteswap.h>
  25. #include <ipxe/in.h>
  26. #include <ipxe/iobuf.h>
  27. #include <ipxe/tcpip.h>
  28. #include <ipxe/ipv6.h>
  29. #include <ipxe/icmpv6.h>
  30. #include <ipxe/neighbour.h>
  31. #include <ipxe/dhcpv6.h>
  32. #include <ipxe/ndp.h>
  33. /** @file
  34. *
  35. * IPv6 neighbour discovery protocol
  36. *
  37. */
  38. static struct ipv6conf * ipv6conf_demux ( struct net_device *netdev );
  39. static int
  40. ipv6conf_rx_router_advertisement ( struct net_device *netdev,
  41. struct in6_addr *router,
  42. struct ndp_router_advertisement_header *radv,
  43. size_t len );
  44. /**
  45. * Transmit NDP packet with link-layer address option
  46. *
  47. * @v netdev Network device
  48. * @v sin6_src Source socket address
  49. * @v sin6_dest Destination socket address
  50. * @v data NDP header
  51. * @v len Size of NDP header
  52. * @v option_type NDP option type
  53. * @ret rc Return status code
  54. */
  55. static int ndp_tx_ll_addr ( struct net_device *netdev,
  56. struct sockaddr_in6 *sin6_src,
  57. struct sockaddr_in6 *sin6_dest,
  58. const void *data, size_t len,
  59. unsigned int option_type ) {
  60. struct sockaddr_tcpip *st_src =
  61. ( ( struct sockaddr_tcpip * ) sin6_src );
  62. struct sockaddr_tcpip *st_dest =
  63. ( ( struct sockaddr_tcpip * ) sin6_dest );
  64. struct ll_protocol *ll_protocol = netdev->ll_protocol;
  65. struct io_buffer *iobuf;
  66. struct ndp_ll_addr_option *ll_addr_opt;
  67. union ndp_header *ndp;
  68. size_t option_len;
  69. int rc;
  70. /* Allocate and populate buffer */
  71. option_len = ( ( sizeof ( *ll_addr_opt ) +
  72. ll_protocol->ll_addr_len + NDP_OPTION_BLKSZ - 1 ) &
  73. ~( NDP_OPTION_BLKSZ - 1 ) );
  74. iobuf = alloc_iob ( MAX_LL_NET_HEADER_LEN + len + option_len );
  75. if ( ! iobuf )
  76. return -ENOMEM;
  77. iob_reserve ( iobuf, MAX_LL_NET_HEADER_LEN );
  78. memcpy ( iob_put ( iobuf, len ), data, len );
  79. ll_addr_opt = iob_put ( iobuf, option_len );
  80. ll_addr_opt->header.type = option_type;
  81. ll_addr_opt->header.blocks = ( option_len / NDP_OPTION_BLKSZ );
  82. memcpy ( ll_addr_opt->ll_addr, netdev->ll_addr,
  83. ll_protocol->ll_addr_len );
  84. ndp = iobuf->data;
  85. ndp->icmp.chksum = tcpip_chksum ( ndp, ( len + option_len ) );
  86. /* Transmit packet */
  87. if ( ( rc = tcpip_tx ( iobuf, &icmpv6_protocol, st_src, st_dest,
  88. netdev, &ndp->icmp.chksum ) ) != 0 ) {
  89. DBGC ( netdev, "NDP %s could not transmit packet: %s\n",
  90. netdev->name, strerror ( rc ) );
  91. return rc;
  92. }
  93. return 0;
  94. }
  95. /**
  96. * Transmit NDP neighbour discovery request
  97. *
  98. * @v netdev Network device
  99. * @v net_protocol Network-layer protocol
  100. * @v net_dest Destination network-layer address
  101. * @v net_source Source network-layer address
  102. * @ret rc Return status code
  103. */
  104. static int ndp_tx_request ( struct net_device *netdev,
  105. struct net_protocol *net_protocol __unused,
  106. const void *net_dest, const void *net_source ) {
  107. struct sockaddr_in6 sin6_src;
  108. struct sockaddr_in6 sin6_dest;
  109. struct ndp_neighbour_header neigh;
  110. int rc;
  111. /* Construct source address */
  112. memset ( &sin6_src, 0, sizeof ( sin6_src ) );
  113. sin6_src.sin6_family = AF_INET6;
  114. memcpy ( &sin6_src.sin6_addr, net_source,
  115. sizeof ( sin6_src.sin6_addr ) );
  116. /* Construct multicast destination address */
  117. memset ( &sin6_dest, 0, sizeof ( sin6_dest ) );
  118. sin6_dest.sin6_family = AF_INET6;
  119. sin6_dest.sin6_scope_id = netdev->index;
  120. ipv6_solicited_node ( &sin6_dest.sin6_addr, net_dest );
  121. /* Construct neighbour header */
  122. memset ( &neigh, 0, sizeof ( neigh ) );
  123. neigh.icmp.type = ICMPV6_NEIGHBOUR_SOLICITATION;
  124. memcpy ( &neigh.target, net_dest, sizeof ( neigh.target ) );
  125. /* Transmit neighbour discovery packet */
  126. if ( ( rc = ndp_tx_ll_addr ( netdev, &sin6_src, &sin6_dest, &neigh,
  127. sizeof ( neigh ),
  128. NDP_OPT_LL_SOURCE ) ) != 0 )
  129. return rc;
  130. return 0;
  131. }
  132. /** NDP neighbour discovery protocol */
  133. struct neighbour_discovery ndp_discovery = {
  134. .name = "NDP",
  135. .tx_request = ndp_tx_request,
  136. };
  137. /**
  138. * Transmit NDP router solicitation
  139. *
  140. * @v netdev Network device
  141. * @ret rc Return status code
  142. */
  143. static int ndp_tx_router_solicitation ( struct net_device *netdev ) {
  144. struct ndp_router_solicitation_header rsol;
  145. struct sockaddr_in6 sin6_dest;
  146. int rc;
  147. /* Construct multicast destination address */
  148. memset ( &sin6_dest, 0, sizeof ( sin6_dest ) );
  149. sin6_dest.sin6_family = AF_INET6;
  150. sin6_dest.sin6_scope_id = netdev->index;
  151. ipv6_all_routers ( &sin6_dest.sin6_addr );
  152. /* Construct router solicitation */
  153. memset ( &rsol, 0, sizeof ( rsol ) );
  154. rsol.icmp.type = ICMPV6_ROUTER_SOLICITATION;
  155. /* Transmit packet */
  156. if ( ( rc = ndp_tx_ll_addr ( netdev, NULL, &sin6_dest, &rsol,
  157. sizeof ( rsol ), NDP_OPT_LL_SOURCE ) ) !=0)
  158. return rc;
  159. return 0;
  160. }
  161. /**
  162. * Process NDP neighbour solicitation source link-layer address option
  163. *
  164. * @v netdev Network device
  165. * @v sin6_src Source socket address
  166. * @v ndp NDP packet
  167. * @v option NDP option
  168. * @v len NDP option length
  169. * @ret rc Return status code
  170. */
  171. static int
  172. ndp_rx_neighbour_solicitation_ll_source ( struct net_device *netdev,
  173. struct sockaddr_in6 *sin6_src,
  174. union ndp_header *ndp,
  175. union ndp_option *option,
  176. size_t len ) {
  177. struct ndp_neighbour_header *neigh = &ndp->neigh;
  178. struct ndp_ll_addr_option *ll_addr_opt = &option->ll_addr;
  179. struct ll_protocol *ll_protocol = netdev->ll_protocol;
  180. int rc;
  181. /* Silently ignore neighbour solicitations for addresses we do
  182. * not own.
  183. */
  184. if ( ! ipv6_has_addr ( netdev, &neigh->target ) )
  185. return 0;
  186. /* Sanity check */
  187. if ( offsetof ( typeof ( *ll_addr_opt ),
  188. ll_addr[ll_protocol->ll_addr_len] ) > len ) {
  189. DBGC ( netdev, "NDP %s neighbour solicitation link-layer "
  190. "address option too short at %zd bytes\n",
  191. netdev->name, len );
  192. return -EINVAL;
  193. }
  194. /* Create or update neighbour cache entry */
  195. if ( ( rc = neighbour_define ( netdev, &ipv6_protocol,
  196. &sin6_src->sin6_addr,
  197. ll_addr_opt->ll_addr ) ) != 0 ) {
  198. DBGC ( netdev, "NDP %s could not define %s => %s: %s\n",
  199. netdev->name, inet6_ntoa ( &sin6_src->sin6_addr ),
  200. ll_protocol->ntoa ( ll_addr_opt->ll_addr ),
  201. strerror ( rc ) );
  202. return rc;
  203. }
  204. /* Convert neighbour header to advertisement */
  205. memset ( neigh, 0, offsetof ( typeof ( *neigh ), target ) );
  206. neigh->icmp.type = ICMPV6_NEIGHBOUR_ADVERTISEMENT;
  207. neigh->flags = ( NDP_NEIGHBOUR_SOLICITED | NDP_NEIGHBOUR_OVERRIDE );
  208. /* Send neighbour advertisement */
  209. if ( ( rc = ndp_tx_ll_addr ( netdev, NULL, sin6_src, neigh,
  210. sizeof ( *neigh ),
  211. NDP_OPT_LL_TARGET ) ) != 0 )
  212. return rc;
  213. return 0;
  214. }
  215. /**
  216. * Process NDP neighbour advertisement target link-layer address option
  217. *
  218. * @v netdev Network device
  219. * @v sin6_src Source socket address
  220. * @v ndp NDP packet
  221. * @v option NDP option
  222. * @v len NDP option length
  223. * @ret rc Return status code
  224. */
  225. static int
  226. ndp_rx_neighbour_advertisement_ll_target ( struct net_device *netdev,
  227. struct sockaddr_in6 *sin6_src
  228. __unused,
  229. union ndp_header *ndp,
  230. union ndp_option *option,
  231. size_t len ) {
  232. struct ndp_neighbour_header *neigh = &ndp->neigh;
  233. struct ndp_ll_addr_option *ll_addr_opt = &option->ll_addr;
  234. struct ll_protocol *ll_protocol = netdev->ll_protocol;
  235. int rc;
  236. /* Sanity check */
  237. if ( offsetof ( typeof ( *ll_addr_opt ),
  238. ll_addr[ll_protocol->ll_addr_len] ) > len ) {
  239. DBGC ( netdev, "NDP %s neighbour advertisement link-layer "
  240. "address option too short at %zd bytes\n",
  241. netdev->name, len );
  242. return -EINVAL;
  243. }
  244. /* Update neighbour cache entry, if any */
  245. if ( ( rc = neighbour_update ( netdev, &ipv6_protocol, &neigh->target,
  246. ll_addr_opt->ll_addr ) ) != 0 ) {
  247. DBGC ( netdev, "NDP %s could not update %s => %s: %s\n",
  248. netdev->name, inet6_ntoa ( &neigh->target ),
  249. ll_protocol->ntoa ( ll_addr_opt->ll_addr ),
  250. strerror ( rc ) );
  251. return rc;
  252. }
  253. return 0;
  254. }
  255. /**
  256. * Process NDP router advertisement source link-layer address option
  257. *
  258. * @v netdev Network device
  259. * @v sin6_src Source socket address
  260. * @v ndp NDP packet
  261. * @v option NDP option
  262. * @v len NDP option length
  263. * @ret rc Return status code
  264. */
  265. static int
  266. ndp_rx_router_advertisement_ll_source ( struct net_device *netdev,
  267. struct sockaddr_in6 *sin6_src,
  268. union ndp_header *ndp __unused,
  269. union ndp_option *option, size_t len ) {
  270. struct ndp_ll_addr_option *ll_addr_opt = &option->ll_addr;
  271. struct ll_protocol *ll_protocol = netdev->ll_protocol;
  272. int rc;
  273. /* Sanity check */
  274. if ( offsetof ( typeof ( *ll_addr_opt ),
  275. ll_addr[ll_protocol->ll_addr_len] ) > len ) {
  276. DBGC ( netdev, "NDP %s router advertisement link-layer address "
  277. "option too short at %zd bytes\n", netdev->name, len );
  278. return -EINVAL;
  279. }
  280. /* Define neighbour cache entry */
  281. if ( ( rc = neighbour_define ( netdev, &ipv6_protocol,
  282. &sin6_src->sin6_addr,
  283. ll_addr_opt->ll_addr ) ) != 0 ) {
  284. DBGC ( netdev, "NDP %s could not define %s => %s: %s\n",
  285. netdev->name, inet6_ntoa ( &sin6_src->sin6_addr ),
  286. ll_protocol->ntoa ( ll_addr_opt->ll_addr ),
  287. strerror ( rc ) );
  288. return rc;
  289. }
  290. return 0;
  291. }
  292. /**
  293. * Process NDP router advertisement prefix information option
  294. *
  295. * @v netdev Network device
  296. * @v sin6_src Source socket address
  297. * @v ndp NDP packet
  298. * @v option NDP option
  299. * @v len NDP option length
  300. * @ret rc Return status code
  301. */
  302. static int
  303. ndp_rx_router_advertisement_prefix ( struct net_device *netdev,
  304. struct sockaddr_in6 *sin6_src,
  305. union ndp_header *ndp,
  306. union ndp_option *option, size_t len ) {
  307. struct ndp_router_advertisement_header *radv = &ndp->radv;
  308. struct ndp_prefix_information_option *prefix_opt = &option->prefix;
  309. /* Sanity check */
  310. if ( sizeof ( *prefix_opt ) > len ) {
  311. DBGC ( netdev, "NDP %s router advertisement prefix option too "
  312. "short at %zd bytes\n", netdev->name, len );
  313. return -EINVAL;
  314. }
  315. DBGC ( netdev, "NDP %s found %sdefault router %s ",
  316. netdev->name, ( radv->lifetime ? "" : "non-" ),
  317. inet6_ntoa ( &sin6_src->sin6_addr ) );
  318. DBGC ( netdev, "for %s-link %sautonomous prefix %s/%d\n",
  319. ( ( prefix_opt->flags & NDP_PREFIX_ON_LINK ) ? "on" : "off" ),
  320. ( ( prefix_opt->flags & NDP_PREFIX_AUTONOMOUS ) ? "" : "non-" ),
  321. inet6_ntoa ( &prefix_opt->prefix ), prefix_opt->prefix_len );
  322. return 0;
  323. }
  324. /** An NDP option handler */
  325. struct ndp_option_handler {
  326. /** ICMPv6 type */
  327. uint8_t icmp_type;
  328. /** Option type */
  329. uint8_t option_type;
  330. /**
  331. * Handle received option
  332. *
  333. * @v netdev Network device
  334. * @v sin6_src Source socket address
  335. * @v ndp NDP packet
  336. * @v option NDP option
  337. * @ret rc Return status code
  338. */
  339. int ( * rx ) ( struct net_device *netdev, struct sockaddr_in6 *sin6_src,
  340. union ndp_header *ndp, union ndp_option *option,
  341. size_t len );
  342. };
  343. /** NDP option handlers */
  344. static struct ndp_option_handler ndp_option_handlers[] = {
  345. {
  346. .icmp_type = ICMPV6_NEIGHBOUR_SOLICITATION,
  347. .option_type = NDP_OPT_LL_SOURCE,
  348. .rx = ndp_rx_neighbour_solicitation_ll_source,
  349. },
  350. {
  351. .icmp_type = ICMPV6_NEIGHBOUR_ADVERTISEMENT,
  352. .option_type = NDP_OPT_LL_TARGET,
  353. .rx = ndp_rx_neighbour_advertisement_ll_target,
  354. },
  355. {
  356. .icmp_type = ICMPV6_ROUTER_ADVERTISEMENT,
  357. .option_type = NDP_OPT_LL_SOURCE,
  358. .rx = ndp_rx_router_advertisement_ll_source,
  359. },
  360. {
  361. .icmp_type = ICMPV6_ROUTER_ADVERTISEMENT,
  362. .option_type = NDP_OPT_PREFIX,
  363. .rx = ndp_rx_router_advertisement_prefix,
  364. },
  365. };
  366. /**
  367. * Process received NDP option
  368. *
  369. * @v netdev Network device
  370. * @v sin6_src Source socket address
  371. * @v ndp NDP packet
  372. * @v option NDP option
  373. * @v len Option length
  374. * @ret rc Return status code
  375. */
  376. static int ndp_rx_option ( struct net_device *netdev,
  377. struct sockaddr_in6 *sin6_src, union ndp_header *ndp,
  378. union ndp_option *option, size_t len ) {
  379. struct ndp_option_handler *handler;
  380. unsigned int i;
  381. /* Locate a suitable option handler, if any */
  382. for ( i = 0 ; i < ( sizeof ( ndp_option_handlers ) /
  383. sizeof ( ndp_option_handlers[0] ) ) ; i++ ) {
  384. handler = &ndp_option_handlers[i];
  385. if ( ( handler->icmp_type == ndp->icmp.type ) &&
  386. ( handler->option_type == option->header.type ) ) {
  387. return handler->rx ( netdev, sin6_src, ndp,
  388. option, len );
  389. }
  390. }
  391. /* Silently ignore unknown options as per RFC 4861 */
  392. return 0;
  393. }
  394. /**
  395. * Process received NDP packet options
  396. *
  397. * @v netdev Network device
  398. * @v sin6_src Source socket address
  399. * @v ndp NDP header
  400. * @v offset Offset to NDP options
  401. * @v len Length of NDP packet
  402. * @ret rc Return status code
  403. */
  404. static int ndp_rx_options ( struct net_device *netdev,
  405. struct sockaddr_in6 *sin6_src,
  406. union ndp_header *ndp, size_t offset, size_t len ) {
  407. union ndp_option *option;
  408. size_t remaining;
  409. size_t option_len;
  410. int rc;
  411. /* Sanity check */
  412. if ( len < offset ) {
  413. DBGC ( netdev, "NDP %s packet too short at %zd bytes (min %zd "
  414. "bytes)\n", netdev->name, len, offset );
  415. return -EINVAL;
  416. }
  417. /* Search for option */
  418. option = ( ( ( void * ) ndp ) + offset );
  419. remaining = ( len - offset );
  420. while ( remaining ) {
  421. /* Sanity check */
  422. if ( ( remaining < sizeof ( option->header ) ) ||
  423. ( option->header.blocks == 0 ) ||
  424. ( remaining < ( option->header.blocks *
  425. NDP_OPTION_BLKSZ ) ) ) {
  426. DBGC ( netdev, "NDP %s bad option length:\n",
  427. netdev->name );
  428. DBGC_HDA ( netdev, 0, option, remaining );
  429. return -EINVAL;
  430. }
  431. option_len = ( option->header.blocks * NDP_OPTION_BLKSZ );
  432. /* Handle option */
  433. if ( ( rc = ndp_rx_option ( netdev, sin6_src, ndp, option,
  434. option_len ) ) != 0 )
  435. return rc;
  436. /* Move to next option */
  437. option = ( ( ( void * ) option ) + option_len );
  438. remaining -= option_len;
  439. }
  440. return 0;
  441. }
  442. /**
  443. * Process received NDP neighbour solicitation or advertisement
  444. *
  445. * @v iobuf I/O buffer
  446. * @v netdev Network device
  447. * @v sin6_src Source socket address
  448. * @v sin6_dest Destination socket address
  449. * @ret rc Return status code
  450. */
  451. static int ndp_rx_neighbour ( struct io_buffer *iobuf,
  452. struct net_device *netdev,
  453. struct sockaddr_in6 *sin6_src,
  454. struct sockaddr_in6 *sin6_dest __unused ) {
  455. union ndp_header *ndp = iobuf->data;
  456. struct ndp_neighbour_header *neigh = &ndp->neigh;
  457. size_t len = iob_len ( iobuf );
  458. int rc;
  459. /* Process options */
  460. if ( ( rc = ndp_rx_options ( netdev, sin6_src, ndp,
  461. offsetof ( typeof ( *neigh ), option ),
  462. len ) ) != 0 )
  463. goto err_options;
  464. err_options:
  465. free_iob ( iobuf );
  466. return rc;
  467. }
  468. /**
  469. * Process received NDP router advertisement
  470. *
  471. * @v iobuf I/O buffer
  472. * @v netdev Network device
  473. * @v sin6_src Source socket address
  474. * @v sin6_dest Destination socket address
  475. * @ret rc Return status code
  476. */
  477. static int
  478. ndp_rx_router_advertisement ( struct io_buffer *iobuf,
  479. struct net_device *netdev,
  480. struct sockaddr_in6 *sin6_src,
  481. struct sockaddr_in6 *sin6_dest __unused ) {
  482. union ndp_header *ndp = iobuf->data;
  483. struct ndp_router_advertisement_header *radv = &ndp->radv;
  484. struct in6_addr *router = &sin6_src->sin6_addr;
  485. size_t len = iob_len ( iobuf );
  486. int rc;
  487. /* Process options */
  488. if ( ( rc = ndp_rx_options ( netdev, sin6_src, ndp,
  489. offsetof ( typeof ( *radv ), option ),
  490. len ) ) != 0 )
  491. goto err_options;
  492. /* Pass to IPv6 autoconfiguration */
  493. if ( ( rc = ipv6conf_rx_router_advertisement ( netdev, router,
  494. radv, len ) ) != 0 )
  495. goto err_ipv6conf;
  496. err_ipv6conf:
  497. err_options:
  498. free_iob ( iobuf );
  499. return rc;
  500. }
  501. /** NDP ICMPv6 handlers */
  502. struct icmpv6_handler ndp_handlers[] __icmpv6_handler = {
  503. {
  504. .type = ICMPV6_NEIGHBOUR_SOLICITATION,
  505. .rx = ndp_rx_neighbour,
  506. },
  507. {
  508. .type = ICMPV6_NEIGHBOUR_ADVERTISEMENT,
  509. .rx = ndp_rx_neighbour,
  510. },
  511. {
  512. .type = ICMPV6_ROUTER_ADVERTISEMENT,
  513. .rx = ndp_rx_router_advertisement,
  514. },
  515. };
  516. /****************************************************************************
  517. *
  518. * NDP settings
  519. *
  520. */
  521. /** An NDP prefix settings block */
  522. struct ndp_prefix_settings {
  523. /** Settings interface */
  524. struct settings settings;
  525. /** Name */
  526. char name[4];
  527. /** Prefix information option */
  528. struct ndp_prefix_information_option *prefix;
  529. };
  530. /** An NDP settings block */
  531. struct ndp_settings {
  532. /** Reference counter */
  533. struct refcnt refcnt;
  534. /** Settings interface */
  535. struct settings settings;
  536. /** Router address */
  537. struct in6_addr router;
  538. /** Router lifetime */
  539. unsigned int lifetime;
  540. /** Length of NDP options */
  541. size_t len;
  542. /** NDP options */
  543. union ndp_option options[0];
  544. };
  545. /** NDP settings scope */
  546. static const struct settings_scope ndp_settings_scope;
  547. /**
  548. * Construct NDP tag
  549. *
  550. * @v type NDP option type
  551. * @v offset Starting offset of data
  552. * @v len Length of data (or 0 to use all remaining data)
  553. * @ret tag NDP tag
  554. */
  555. #define NDP_TAG( type, offset, len ) \
  556. ( ( (len) << 16 ) | ( (offset) << 8 ) | (type) )
  557. /**
  558. * Extract NDP tag type
  559. *
  560. * @v tag NDP tag
  561. * @ret type NDP option type
  562. */
  563. #define NDP_TAG_TYPE( tag ) ( ( (tag) >> 0 ) & 0xff )
  564. /**
  565. * Extract NDP tag offset
  566. *
  567. * @v tag NDP tag
  568. * @ret offset Starting offset of data
  569. */
  570. #define NDP_TAG_OFFSET( tag ) ( ( (tag) >> 8 ) & 0xff )
  571. /**
  572. * Extract NDP tag length
  573. *
  574. * @v tag NDP tag
  575. * @ret len Length of data (or 0 to use all remaining data)
  576. */
  577. #define NDP_TAG_LEN( tag ) ( ( (tag) >> 16 ) & 0xff )
  578. /**
  579. * Extract NDP tag instance
  580. *
  581. * @v tag NDP tag
  582. * @ret instance Instance
  583. */
  584. #define NDP_TAG_INSTANCE( tag ) ( ( (tag) >> 24 ) & 0xff )
  585. /**
  586. * Check applicability of NDP setting
  587. *
  588. * @v settings Settings block
  589. * @v setting Setting to fetch
  590. * @ret applies Setting applies within this settings block
  591. */
  592. static int ndp_applies ( struct settings *settings __unused,
  593. const struct setting *setting ) {
  594. return ( setting->scope == &ndp_settings_scope );
  595. }
  596. /**
  597. * Fetch value of NDP setting
  598. *
  599. * @v settings Settings block
  600. * @v setting Setting to fetch
  601. * @v data Buffer to fill with setting data
  602. * @v len Length of buffer
  603. * @ret len Length of setting data, or negative error
  604. */
  605. static int ndp_fetch ( struct settings *settings,
  606. struct setting *setting,
  607. void *data, size_t len ) {
  608. struct ndp_settings *ndpset =
  609. container_of ( settings, struct ndp_settings, settings );
  610. struct net_device *netdev =
  611. container_of ( settings->parent, struct net_device,
  612. settings.settings );
  613. union ndp_option *option;
  614. unsigned int tag_type;
  615. unsigned int tag_offset;
  616. unsigned int tag_len;
  617. unsigned int tag_instance;
  618. size_t offset;
  619. size_t option_len;
  620. void *option_data;
  621. /* Parse setting tag */
  622. tag_type = NDP_TAG_TYPE ( setting->tag );
  623. tag_offset = NDP_TAG_OFFSET ( setting->tag );
  624. tag_len = NDP_TAG_LEN ( setting->tag );
  625. tag_instance = NDP_TAG_INSTANCE ( setting->tag );
  626. /* Scan through NDP options for requested type. We can assume
  627. * that the options are well-formed, otherwise they would have
  628. * been rejected prior to being stored.
  629. */
  630. for ( offset = 0 ; offset < ndpset->len ; offset += option_len ) {
  631. /* Calculate option length */
  632. option = ( ( ( void * ) ndpset->options ) + offset );
  633. option_len = ( option->header.blocks * NDP_OPTION_BLKSZ );
  634. /* Skip options that do not match this tag */
  635. if ( option->header.type != tag_type )
  636. continue;
  637. /* Skip previous instances of this option */
  638. if ( tag_instance-- != 0 )
  639. continue;
  640. /* Sanity check */
  641. if ( ( tag_offset + tag_len ) > option_len ) {
  642. DBGC ( netdev, "NDP %s option %d too short\n",
  643. netdev->name, tag_type );
  644. return -EINVAL;
  645. }
  646. if ( ! tag_len )
  647. tag_len = ( option_len - tag_offset );
  648. option_data = ( ( ( void * ) option ) + tag_offset );
  649. /* Copy data to output buffer */
  650. if ( len > tag_len )
  651. len = tag_len;
  652. memcpy ( data, option_data, len );
  653. /* Default to hex if no type is specified */
  654. if ( ! setting->type )
  655. setting->type = &setting_type_hex;
  656. return tag_len;
  657. }
  658. return -ENOENT;
  659. }
  660. /** NDP settings operations */
  661. static struct settings_operations ndp_settings_operations = {
  662. .applies = ndp_applies,
  663. .fetch = ndp_fetch,
  664. };
  665. /**
  666. * Check applicability of NDP per-prefix setting
  667. *
  668. * @v settings Settings block
  669. * @v setting Setting to fetch
  670. * @ret applies Setting applies within this settings block
  671. */
  672. static int ndp_prefix_applies ( struct settings *settings __unused,
  673. const struct setting *setting ) {
  674. return ( setting->scope == &ipv6_settings_scope );
  675. }
  676. /**
  677. * Fetch value of NDP IPv6 address setting
  678. *
  679. * @v settings Settings block
  680. * @v data Buffer to fill with setting data
  681. * @v len Length of buffer
  682. * @ret len Length of setting data, or negative error
  683. */
  684. static int ndp_prefix_fetch_ip6 ( struct settings *settings, void *data,
  685. size_t len ) {
  686. struct ndp_prefix_settings *prefset =
  687. container_of ( settings, struct ndp_prefix_settings, settings );
  688. struct ndp_settings *ndpset =
  689. container_of ( settings->parent, struct ndp_settings, settings);
  690. struct net_device *netdev =
  691. container_of ( ndpset->settings.parent, struct net_device,
  692. settings.settings );
  693. struct ndp_prefix_information_option *prefix = prefset->prefix;
  694. struct in6_addr ip6;
  695. int prefix_len;
  696. /* Skip dead prefixes */
  697. if ( ! prefix->valid )
  698. return -ENOENT;
  699. /* Construct IPv6 address via SLAAC, if applicable */
  700. memcpy ( &ip6, &prefix->prefix, sizeof ( ip6 ) );
  701. if ( prefix->flags & NDP_PREFIX_AUTONOMOUS ) {
  702. prefix_len = ipv6_eui64 ( &ip6, netdev );
  703. if ( prefix_len < 0 )
  704. return prefix_len;
  705. if ( prefix_len != prefix->prefix_len )
  706. return -EINVAL;
  707. }
  708. /* Fill in IPv6 address */
  709. if ( len > sizeof ( ip6 ) )
  710. len = sizeof ( ip6 );
  711. memcpy ( data, &ip6, len );
  712. return sizeof ( ip6 );
  713. }
  714. /**
  715. * Fetch value of NDP prefix length setting
  716. *
  717. * @v settings Settings block
  718. * @v data Buffer to fill with setting data
  719. * @v len Length of buffer
  720. * @ret len Length of setting data, or negative error
  721. */
  722. static int ndp_prefix_fetch_len6 ( struct settings *settings, void *data,
  723. size_t len ) {
  724. struct ndp_prefix_settings *prefset =
  725. container_of ( settings, struct ndp_prefix_settings, settings );
  726. struct ndp_prefix_information_option *prefix = prefset->prefix;
  727. uint8_t *len6;
  728. /* Fill in prefix length */
  729. if ( len >= sizeof ( *len6 ) ) {
  730. /* We treat an off-link prefix as having a prefix
  731. * length covering the entire IPv6 address.
  732. */
  733. len6 = data;
  734. *len6 = ( ( prefix->flags & NDP_PREFIX_ON_LINK ) ?
  735. prefix->prefix_len : -1UL );
  736. }
  737. return sizeof ( *len6 );
  738. }
  739. /**
  740. * Fetch value of NDP router address setting
  741. *
  742. * @v settings Settings block
  743. * @v data Buffer to fill with setting data
  744. * @v len Length of buffer
  745. * @ret len Length of setting data, or negative error
  746. */
  747. static int ndp_prefix_fetch_gateway6 ( struct settings *settings,
  748. void *data, size_t len ) {
  749. struct ndp_settings *ndpset =
  750. container_of ( settings->parent, struct ndp_settings, settings);
  751. /* Treat non-routing router as non-existent */
  752. if ( ! ndpset->lifetime )
  753. return -ENOENT;
  754. /* Fill in router address */
  755. if ( len > sizeof ( ndpset->router ) )
  756. len = sizeof ( ndpset->router );
  757. memcpy ( data, &ndpset->router, len );
  758. return sizeof ( ndpset->router );
  759. }
  760. /** An NDP per-prefix setting operation */
  761. struct ndp_prefix_operation {
  762. /** Generic setting */
  763. const struct setting *setting;
  764. /**
  765. * Fetch value of setting
  766. *
  767. * @v settings Settings block
  768. * @v data Buffer to fill with setting data
  769. * @v len Length of buffer
  770. * @ret len Length of setting data, or negative error
  771. */
  772. int ( * fetch ) ( struct settings *settings, void *data, size_t len );
  773. };
  774. /** NDP per-prefix settings operations */
  775. static struct ndp_prefix_operation ndp_prefix_operations[] = {
  776. { &ip6_setting, ndp_prefix_fetch_ip6 },
  777. { &len6_setting, ndp_prefix_fetch_len6 },
  778. { &gateway6_setting, ndp_prefix_fetch_gateway6 },
  779. };
  780. /**
  781. * Fetch value of NDP pre-prefix setting
  782. *
  783. * @v settings Settings block
  784. * @v setting Setting to fetch
  785. * @v data Buffer to fill with setting data
  786. * @v len Length of buffer
  787. * @ret len Length of setting data, or negative error
  788. */
  789. static int ndp_prefix_fetch ( struct settings *settings,
  790. struct setting *setting,
  791. void *data, size_t len ) {
  792. struct ndp_prefix_operation *op;
  793. unsigned int i;
  794. /* Handle per-prefix settings */
  795. for ( i = 0 ; i < ( sizeof ( ndp_prefix_operations ) /
  796. sizeof ( ndp_prefix_operations[0] ) ) ; i++ ) {
  797. op = &ndp_prefix_operations[i];
  798. if ( setting_cmp ( setting, op->setting ) == 0 )
  799. return op->fetch ( settings, data, len );
  800. }
  801. return -ENOENT;
  802. }
  803. /** NDP per-prefix settings operations */
  804. static struct settings_operations ndp_prefix_settings_operations = {
  805. .applies = ndp_prefix_applies,
  806. .fetch = ndp_prefix_fetch,
  807. };
  808. /**
  809. * Register NDP settings
  810. *
  811. * @v netdev Network device
  812. * @v router Router address
  813. * @v lifetime Router lifetime
  814. * @v options NDP options
  815. * @v len Length of options
  816. * @ret rc Return status code
  817. */
  818. static int ndp_register_settings ( struct net_device *netdev,
  819. struct in6_addr *router,
  820. unsigned int lifetime,
  821. union ndp_option *options, size_t len ) {
  822. struct settings *parent = netdev_settings ( netdev );
  823. union ndp_option *option;
  824. struct ndp_settings *ndpset;
  825. struct ndp_prefix_settings *prefset;
  826. size_t offset;
  827. size_t option_len;
  828. unsigned int prefixes;
  829. unsigned int instance;
  830. int order;
  831. int rc;
  832. /* Count number of prefix options. We can assume that the
  833. * options are well-formed, otherwise they would have been
  834. * rejected prior to being stored.
  835. */
  836. order = IPV6_ORDER_PREFIX_ONLY;
  837. for ( prefixes = 0, offset = 0 ; offset < len ; offset += option_len ) {
  838. /* Skip non-prefix options */
  839. option = ( ( ( void * ) options ) + offset );
  840. option_len = ( option->header.blocks * NDP_OPTION_BLKSZ );
  841. if ( option->header.type != NDP_OPT_PREFIX )
  842. continue;
  843. /* Count number of prefixes */
  844. prefixes++;
  845. /* Increase overall order if we have SLAAC addresses */
  846. if ( option->prefix.flags & NDP_PREFIX_AUTONOMOUS )
  847. order = IPV6_ORDER_SLAAC;
  848. }
  849. /* Allocate and initialise structure */
  850. ndpset = zalloc ( sizeof ( *ndpset ) + len +
  851. ( prefixes * sizeof ( *prefset ) ) );
  852. if ( ! ndpset ) {
  853. rc = -ENOMEM;
  854. goto err_alloc;
  855. }
  856. ref_init ( &ndpset->refcnt, NULL );
  857. settings_init ( &ndpset->settings, &ndp_settings_operations,
  858. &ndpset->refcnt, &ndp_settings_scope );
  859. ndpset->settings.order = order;
  860. memcpy ( &ndpset->router, router, sizeof ( ndpset->router ) );
  861. ndpset->lifetime = lifetime;
  862. ndpset->len = len;
  863. memcpy ( ndpset->options, options, len );
  864. prefset = ( ( ( void * ) ndpset->options ) + len );
  865. /* Register settings */
  866. if ( ( rc = register_settings ( &ndpset->settings, parent,
  867. NDP_SETTINGS_NAME ) ) != 0 )
  868. goto err_register;
  869. /* Construct and register per-prefix settings */
  870. for ( instance = 0, offset = 0 ; offset < len ; offset += option_len ) {
  871. /* Skip non-prefix options */
  872. option = ( ( ( void * ) ndpset->options ) + offset );
  873. option_len = ( option->header.blocks * NDP_OPTION_BLKSZ );
  874. if ( option->header.type != NDP_OPT_PREFIX )
  875. continue;
  876. /* Initialise structure */
  877. settings_init ( &prefset->settings,
  878. &ndp_prefix_settings_operations,
  879. &ndpset->refcnt, &ndp_settings_scope );
  880. prefset->settings.order =
  881. ( ( option->prefix.flags & NDP_PREFIX_AUTONOMOUS ) ?
  882. IPV6_ORDER_SLAAC : IPV6_ORDER_PREFIX_ONLY );
  883. prefset->prefix = &option->prefix;
  884. snprintf ( prefset->name, sizeof ( prefset->name ), "%d",
  885. instance++ );
  886. /* Register settings */
  887. if ( ( rc = register_settings ( &prefset->settings,
  888. &ndpset->settings,
  889. prefset->name ) ) != 0 )
  890. goto err_register_prefix;
  891. /* Move to next per-prefix settings */
  892. prefset++;
  893. }
  894. assert ( instance == prefixes );
  895. ref_put ( &ndpset->refcnt );
  896. return 0;
  897. err_register_prefix:
  898. unregister_settings ( &ndpset->settings );
  899. err_register:
  900. ref_put ( &ndpset->refcnt );
  901. err_alloc:
  902. return rc;
  903. }
  904. /** DNS server setting */
  905. const struct setting ndp_dns6_setting __setting ( SETTING_IP6_EXTRA, dns6 ) = {
  906. .name = "dns6",
  907. .description = "DNS server",
  908. .tag = NDP_TAG ( NDP_OPT_RDNSS,
  909. offsetof ( struct ndp_rdnss_option, addresses ), 0 ),
  910. .type = &setting_type_ipv6,
  911. .scope = &ndp_settings_scope,
  912. };
  913. /** DNS search list setting */
  914. const struct setting ndp_dnssl_setting __setting ( SETTING_IP_EXTRA, dnssl ) = {
  915. .name = "dnssl",
  916. .description = "DNS search list",
  917. .tag = NDP_TAG ( NDP_OPT_DNSSL,
  918. offsetof ( struct ndp_dnssl_option, names ), 0 ),
  919. .type = &setting_type_dnssl,
  920. .scope = &ndp_settings_scope,
  921. };
  922. /****************************************************************************
  923. *
  924. * IPv6 autoconfiguration
  925. *
  926. */
  927. /** An IPv6 configurator */
  928. struct ipv6conf {
  929. /** Reference count */
  930. struct refcnt refcnt;
  931. /** List of configurators */
  932. struct list_head list;
  933. /** Job control interface */
  934. struct interface job;
  935. /** DHCPv6 interface */
  936. struct interface dhcp;
  937. /** Network device being configured */
  938. struct net_device *netdev;
  939. /** Retransmission timer */
  940. struct retry_timer timer;
  941. };
  942. /** List of IPv6 configurators */
  943. static LIST_HEAD ( ipv6confs );
  944. /**
  945. * Free IPv6 configurator
  946. *
  947. * @v refcnt Reference count
  948. */
  949. static void ipv6conf_free ( struct refcnt *refcnt ) {
  950. struct ipv6conf *ipv6conf =
  951. container_of ( refcnt, struct ipv6conf, refcnt );
  952. netdev_put ( ipv6conf->netdev );
  953. free ( ipv6conf );
  954. }
  955. /**
  956. * Identify IPv6 configurator by network device
  957. *
  958. * @v netdev Network device
  959. * @ret ipv6 IPv6 configurator, or NULL
  960. */
  961. static struct ipv6conf * ipv6conf_demux ( struct net_device *netdev ) {
  962. struct ipv6conf *ipv6conf;
  963. list_for_each_entry ( ipv6conf, &ipv6confs, list ) {
  964. if ( ipv6conf->netdev == netdev )
  965. return ipv6conf;
  966. }
  967. return NULL;
  968. }
  969. /**
  970. * Finish IPv6 autoconfiguration
  971. *
  972. * @v ipv6 IPv6 configurator
  973. * @v rc Reason for finishing
  974. */
  975. static void ipv6conf_done ( struct ipv6conf *ipv6conf, int rc ) {
  976. /* Shut down interfaces */
  977. intf_shutdown ( &ipv6conf->job, rc );
  978. intf_shutdown ( &ipv6conf->dhcp, rc );
  979. /* Stop timer */
  980. stop_timer ( &ipv6conf->timer );
  981. /* Remove from list and drop list's reference */
  982. list_del ( &ipv6conf->list );
  983. ref_put ( &ipv6conf->refcnt );
  984. }
  985. /**
  986. * Handle IPv6 configurator timer expiry
  987. *
  988. * @v timer Retry timer
  989. * @v fail Failure indicator
  990. */
  991. static void ipv6conf_expired ( struct retry_timer *timer, int fail ) {
  992. struct ipv6conf *ipv6conf =
  993. container_of ( timer, struct ipv6conf, timer );
  994. /* If we have failed, terminate autoconfiguration */
  995. if ( fail ) {
  996. ipv6conf_done ( ipv6conf, -ETIMEDOUT );
  997. return;
  998. }
  999. /* Otherwise, transmit router solicitation and restart timer */
  1000. start_timer ( &ipv6conf->timer );
  1001. ndp_tx_router_solicitation ( ipv6conf->netdev );
  1002. }
  1003. /**
  1004. * Handle router advertisement during IPv6 autoconfiguration
  1005. *
  1006. * @v netdev Network device
  1007. * @v router Router address
  1008. * @v radv Router advertisement
  1009. * @v len Length of router advertisement
  1010. * @ret rc Return status code
  1011. *
  1012. * This function assumes that the router advertisement is well-formed,
  1013. * since it must have already passed through option processing.
  1014. */
  1015. static int
  1016. ipv6conf_rx_router_advertisement ( struct net_device *netdev,
  1017. struct in6_addr *router,
  1018. struct ndp_router_advertisement_header *radv,
  1019. size_t len ) {
  1020. struct ipv6conf *ipv6conf;
  1021. size_t option_len;
  1022. int stateful;
  1023. int rc;
  1024. /* Identify IPv6 configurator, if any */
  1025. ipv6conf = ipv6conf_demux ( netdev );
  1026. /* Do nothing unless IPv6 autoconfiguration is in progress */
  1027. if ( ! ipv6conf )
  1028. return 0;
  1029. /* If this is not the first solicited router advertisement, ignore it */
  1030. if ( ! timer_running ( &ipv6conf->timer ) )
  1031. return 0;
  1032. /* Stop router solicitation timer */
  1033. stop_timer ( &ipv6conf->timer );
  1034. /* Register NDP settings */
  1035. option_len = ( len - offsetof ( typeof ( *radv ), option ) );
  1036. if ( ( rc = ndp_register_settings ( netdev, router,
  1037. ntohl ( radv->lifetime ),
  1038. radv->option, option_len ) ) != 0 )
  1039. return rc;
  1040. /* Start DHCPv6 if required */
  1041. if ( radv->flags & ( NDP_ROUTER_MANAGED | NDP_ROUTER_OTHER ) ) {
  1042. stateful = ( radv->flags & NDP_ROUTER_MANAGED );
  1043. if ( ( rc = start_dhcpv6 ( &ipv6conf->dhcp, netdev,
  1044. stateful ) ) != 0 ) {
  1045. DBGC ( netdev, "NDP %s could not start state%s DHCPv6: "
  1046. "%s\n", netdev->name,
  1047. ( stateful ? "ful" : "less" ), strerror ( rc ) );
  1048. ipv6conf_done ( ipv6conf, rc );
  1049. return rc;
  1050. }
  1051. return 0;
  1052. }
  1053. /* Otherwise, terminate autoconfiguration */
  1054. ipv6conf_done ( ipv6conf, 0 );
  1055. return 0;
  1056. }
  1057. /** IPv6 configurator job interface operations */
  1058. static struct interface_operation ipv6conf_job_op[] = {
  1059. INTF_OP ( intf_close, struct ipv6conf *, ipv6conf_done ),
  1060. };
  1061. /** IPv6 configurator job interface descriptor */
  1062. static struct interface_descriptor ipv6conf_job_desc =
  1063. INTF_DESC ( struct ipv6conf, job, ipv6conf_job_op );
  1064. /** IPv6 configurator DHCPv6 interface operations */
  1065. static struct interface_operation ipv6conf_dhcp_op[] = {
  1066. INTF_OP ( intf_close, struct ipv6conf *, ipv6conf_done ),
  1067. };
  1068. /** IPv6 configurator DHCPv6 interface descriptor */
  1069. static struct interface_descriptor ipv6conf_dhcp_desc =
  1070. INTF_DESC ( struct ipv6conf, dhcp, ipv6conf_dhcp_op );
  1071. /**
  1072. * Start IPv6 autoconfiguration
  1073. *
  1074. * @v job Job control interface
  1075. * @v netdev Network device
  1076. * @ret rc Return status code
  1077. */
  1078. int start_ipv6conf ( struct interface *job, struct net_device *netdev ) {
  1079. struct ipv6conf *ipv6conf;
  1080. /* Allocate and initialise structure */
  1081. ipv6conf = zalloc ( sizeof ( *ipv6conf ) );
  1082. if ( ! ipv6conf )
  1083. return -ENOMEM;
  1084. ref_init ( &ipv6conf->refcnt, ipv6conf_free );
  1085. intf_init ( &ipv6conf->job, &ipv6conf_job_desc, &ipv6conf->refcnt );
  1086. intf_init ( &ipv6conf->dhcp, &ipv6conf_dhcp_desc, &ipv6conf->refcnt );
  1087. timer_init ( &ipv6conf->timer, ipv6conf_expired, &ipv6conf->refcnt );
  1088. ipv6conf->netdev = netdev_get ( netdev );
  1089. /* Start timer to initiate router solicitation */
  1090. start_timer_nodelay ( &ipv6conf->timer );
  1091. /* Attach parent interface, transfer reference to list, and return */
  1092. intf_plug_plug ( &ipv6conf->job, job );
  1093. list_add ( &ipv6conf->list, &ipv6confs );
  1094. return 0;
  1095. }
  1096. /** IPv6 network device configurator */
  1097. struct net_device_configurator ipv6_configurator __net_device_configurator = {
  1098. .name = "ipv6",
  1099. .start = start_ipv6conf,
  1100. };