connection_manager.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. package nebula
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/binary"
  6. "fmt"
  7. "log/slog"
  8. "net/netip"
  9. "sync"
  10. "sync/atomic"
  11. "time"
  12. "github.com/rcrowley/go-metrics"
  13. "github.com/slackhq/nebula/cert"
  14. "github.com/slackhq/nebula/config"
  15. "github.com/slackhq/nebula/header"
  16. )
  17. type trafficDecision int
  18. const (
  19. doNothing trafficDecision = 0
  20. deleteTunnel trafficDecision = 1 // delete the hostinfo on our side, do not notify the remote
  21. closeTunnel trafficDecision = 2 // delete the hostinfo and notify the remote
  22. swapPrimary trafficDecision = 3
  23. migrateRelays trafficDecision = 4
  24. tryRehandshake trafficDecision = 5
  25. sendTestPacket trafficDecision = 6
  26. )
  27. type connectionManager struct {
  28. // relayUsed holds which relay localIndexs are in use
  29. relayUsed map[uint32]struct{}
  30. relayUsedLock *sync.RWMutex
  31. hostMap *HostMap
  32. trafficTimer *LockingTimerWheel[uint32]
  33. intf *Interface
  34. punchy *Punchy
  35. // Configuration settings
  36. checkInterval time.Duration
  37. pendingDeletionInterval time.Duration
  38. inactivityTimeout atomic.Int64
  39. dropInactive atomic.Bool
  40. metricsTxPunchy metrics.Counter
  41. l *slog.Logger
  42. }
  43. func newConnectionManagerFromConfig(l *slog.Logger, c *config.C, hm *HostMap, p *Punchy) *connectionManager {
  44. cm := &connectionManager{
  45. hostMap: hm,
  46. l: l,
  47. punchy: p,
  48. relayUsed: make(map[uint32]struct{}),
  49. relayUsedLock: &sync.RWMutex{},
  50. metricsTxPunchy: metrics.GetOrRegisterCounter("messages.tx.punchy", nil),
  51. }
  52. cm.reload(c, true)
  53. c.RegisterReloadCallback(func(c *config.C) {
  54. cm.reload(c, false)
  55. })
  56. return cm
  57. }
  58. func (cm *connectionManager) reload(c *config.C, initial bool) {
  59. if initial {
  60. cm.checkInterval = time.Duration(c.GetInt("timers.connection_alive_interval", 5)) * time.Second
  61. cm.pendingDeletionInterval = time.Duration(c.GetInt("timers.pending_deletion_interval", 10)) * time.Second
  62. // We want at least a minimum resolution of 500ms per tick so that we can hit these intervals
  63. // pretty close to their configured duration.
  64. // The inactivity duration is checked each time a hostinfo ticks through so we don't need the wheel to contain it.
  65. minDuration := min(time.Millisecond*500, cm.checkInterval, cm.pendingDeletionInterval)
  66. maxDuration := max(cm.checkInterval, cm.pendingDeletionInterval)
  67. cm.trafficTimer = NewLockingTimerWheel[uint32](minDuration, maxDuration)
  68. }
  69. if initial || c.HasChanged("tunnels.inactivity_timeout") {
  70. old := cm.getInactivityTimeout()
  71. cm.inactivityTimeout.Store((int64)(c.GetDuration("tunnels.inactivity_timeout", 10*time.Minute)))
  72. if !initial {
  73. cm.l.Info("Inactivity timeout has changed",
  74. "oldDuration", old,
  75. "newDuration", cm.getInactivityTimeout(),
  76. )
  77. }
  78. }
  79. if initial || c.HasChanged("tunnels.drop_inactive") {
  80. old := cm.dropInactive.Load()
  81. cm.dropInactive.Store(c.GetBool("tunnels.drop_inactive", false))
  82. if !initial {
  83. cm.l.Info("Drop inactive setting has changed",
  84. "oldBool", old,
  85. "newBool", cm.dropInactive.Load(),
  86. )
  87. }
  88. }
  89. }
  90. func (cm *connectionManager) getInactivityTimeout() time.Duration {
  91. return (time.Duration)(cm.inactivityTimeout.Load())
  92. }
  93. func (cm *connectionManager) In(h *HostInfo) {
  94. h.in.Store(true)
  95. }
  96. func (cm *connectionManager) Out(h *HostInfo) {
  97. h.out.Store(true)
  98. }
  99. func (cm *connectionManager) RelayUsed(localIndex uint32) {
  100. cm.relayUsedLock.RLock()
  101. // If this already exists, return
  102. if _, ok := cm.relayUsed[localIndex]; ok {
  103. cm.relayUsedLock.RUnlock()
  104. return
  105. }
  106. cm.relayUsedLock.RUnlock()
  107. cm.relayUsedLock.Lock()
  108. cm.relayUsed[localIndex] = struct{}{}
  109. cm.relayUsedLock.Unlock()
  110. }
  111. // getAndResetTrafficCheck returns if there was any inbound or outbound traffic within the last tick and
  112. // resets the state for this local index
  113. func (cm *connectionManager) getAndResetTrafficCheck(h *HostInfo, now time.Time) (bool, bool) {
  114. in := h.in.Swap(false)
  115. out := h.out.Swap(false)
  116. if in || out {
  117. h.lastUsed = now
  118. }
  119. return in, out
  120. }
  121. // AddTrafficWatch must be called for every new HostInfo.
  122. // We will continue to monitor the HostInfo until the tunnel is dropped.
  123. func (cm *connectionManager) AddTrafficWatch(h *HostInfo) {
  124. if h.out.Swap(true) == false {
  125. cm.trafficTimer.Add(h.localIndexId, cm.checkInterval)
  126. }
  127. }
  128. func (cm *connectionManager) Start(ctx context.Context) {
  129. clockSource := time.NewTicker(cm.trafficTimer.t.tickDuration)
  130. defer clockSource.Stop()
  131. p := []byte("")
  132. nb := make([]byte, 12, 12)
  133. out := make([]byte, mtu)
  134. for {
  135. select {
  136. case <-ctx.Done():
  137. return
  138. case now := <-clockSource.C:
  139. cm.trafficTimer.Advance(now)
  140. for {
  141. localIndex, has := cm.trafficTimer.Purge()
  142. if !has {
  143. break
  144. }
  145. cm.doTrafficCheck(localIndex, p, nb, out, now)
  146. }
  147. }
  148. }
  149. }
  150. func (cm *connectionManager) doTrafficCheck(localIndex uint32, p, nb, out []byte, now time.Time) {
  151. decision, hostinfo, primary := cm.makeTrafficDecision(localIndex, now)
  152. switch decision {
  153. case deleteTunnel:
  154. if cm.hostMap.DeleteHostInfo(hostinfo) {
  155. // Only clearing the lighthouse cache if this is the last hostinfo for this vpn ip in the hostmap
  156. cm.intf.lightHouse.DeleteVpnAddrs(hostinfo.vpnAddrs)
  157. }
  158. case closeTunnel:
  159. cm.intf.sendCloseTunnel(hostinfo)
  160. cm.intf.closeTunnel(hostinfo)
  161. case swapPrimary:
  162. cm.swapPrimary(hostinfo, primary)
  163. case migrateRelays:
  164. cm.migrateRelayUsed(hostinfo, primary)
  165. case tryRehandshake:
  166. cm.tryRehandshake(hostinfo)
  167. case sendTestPacket:
  168. cm.intf.SendMessageToHostInfo(header.Test, header.TestRequest, hostinfo, p, nb, out)
  169. }
  170. cm.resetRelayTrafficCheck(hostinfo)
  171. }
  172. func (cm *connectionManager) resetRelayTrafficCheck(hostinfo *HostInfo) {
  173. if hostinfo != nil {
  174. cm.relayUsedLock.Lock()
  175. defer cm.relayUsedLock.Unlock()
  176. // No need to migrate any relays, delete usage info now.
  177. for _, idx := range hostinfo.relayState.CopyRelayForIdxs() {
  178. delete(cm.relayUsed, idx)
  179. }
  180. }
  181. }
  182. func (cm *connectionManager) migrateRelayUsed(oldhostinfo, newhostinfo *HostInfo) {
  183. relayFor := oldhostinfo.relayState.CopyAllRelayFor()
  184. for _, r := range relayFor {
  185. existing, ok := newhostinfo.relayState.QueryRelayForByIp(r.PeerAddr)
  186. var index uint32
  187. var relayFrom netip.Addr
  188. var relayTo netip.Addr
  189. switch {
  190. case ok:
  191. switch existing.State {
  192. case Established, PeerRequested, Disestablished:
  193. // This relay already exists in newhostinfo, then do nothing.
  194. continue
  195. case Requested:
  196. // The relay exists in a Requested state; re-send the request
  197. index = existing.LocalIndex
  198. switch r.Type {
  199. case TerminalType:
  200. relayFrom = cm.intf.myVpnAddrs[0]
  201. relayTo = existing.PeerAddr
  202. case ForwardingType:
  203. relayFrom = existing.PeerAddr
  204. relayTo = newhostinfo.vpnAddrs[0]
  205. default:
  206. // should never happen
  207. panic(fmt.Sprintf("Migrating unknown relay type: %v", r.Type))
  208. }
  209. }
  210. case !ok:
  211. cm.relayUsedLock.RLock()
  212. if _, relayUsed := cm.relayUsed[r.LocalIndex]; !relayUsed {
  213. // The relay hasn't been used; don't migrate it.
  214. cm.relayUsedLock.RUnlock()
  215. continue
  216. }
  217. cm.relayUsedLock.RUnlock()
  218. // The relay doesn't exist at all; create some relay state and send the request.
  219. var err error
  220. index, err = AddRelay(cm.l, newhostinfo, cm.hostMap, r.PeerAddr, nil, r.Type, Requested)
  221. if err != nil {
  222. cm.l.Error("failed to migrate relay to new hostinfo", "error", err)
  223. continue
  224. }
  225. switch r.Type {
  226. case TerminalType:
  227. relayFrom = cm.intf.myVpnAddrs[0]
  228. relayTo = r.PeerAddr
  229. case ForwardingType:
  230. relayFrom = r.PeerAddr
  231. relayTo = newhostinfo.vpnAddrs[0]
  232. default:
  233. // should never happen
  234. panic(fmt.Sprintf("Migrating unknown relay type: %v", r.Type))
  235. }
  236. }
  237. // Send a CreateRelayRequest to the peer.
  238. req := NebulaControl{
  239. Type: NebulaControl_CreateRelayRequest,
  240. InitiatorRelayIndex: index,
  241. }
  242. switch newhostinfo.GetCert().Certificate.Version() {
  243. case cert.Version1:
  244. if !relayFrom.Is4() {
  245. cm.l.Error("can not migrate v1 relay with a v6 network because the relay is not running a current nebula version")
  246. continue
  247. }
  248. if !relayTo.Is4() {
  249. cm.l.Error("can not migrate v1 relay with a v6 remote network because the relay is not running a current nebula version")
  250. continue
  251. }
  252. b := relayFrom.As4()
  253. req.OldRelayFromAddr = binary.BigEndian.Uint32(b[:])
  254. b = relayTo.As4()
  255. req.OldRelayToAddr = binary.BigEndian.Uint32(b[:])
  256. case cert.Version2:
  257. req.RelayFromAddr = netAddrToProtoAddr(relayFrom)
  258. req.RelayToAddr = netAddrToProtoAddr(relayTo)
  259. default:
  260. newhostinfo.logger(cm.l).Error("Unknown certificate version found while attempting to migrate relay")
  261. continue
  262. }
  263. msg, err := req.Marshal()
  264. if err != nil {
  265. cm.l.Error("failed to marshal Control message to migrate relay", "error", err)
  266. } else {
  267. cm.intf.SendMessageToHostInfo(header.Control, 0, newhostinfo, msg, make([]byte, 12), make([]byte, mtu))
  268. cm.l.Info("send CreateRelayRequest",
  269. "relayFrom", req.RelayFromAddr,
  270. "relayTo", req.RelayToAddr,
  271. "initiatorRelayIndex", req.InitiatorRelayIndex,
  272. "responderRelayIndex", req.ResponderRelayIndex,
  273. "vpnAddrs", newhostinfo.vpnAddrs,
  274. )
  275. }
  276. }
  277. }
  278. func (cm *connectionManager) makeTrafficDecision(localIndex uint32, now time.Time) (trafficDecision, *HostInfo, *HostInfo) {
  279. // Read lock the main hostmap to order decisions based on tunnels being the primary tunnel
  280. cm.hostMap.RLock()
  281. defer cm.hostMap.RUnlock()
  282. hostinfo := cm.hostMap.Indexes[localIndex]
  283. if hostinfo == nil {
  284. cm.l.Debug("Not found in hostmap", "localIndex", localIndex)
  285. return doNothing, nil, nil
  286. }
  287. if cm.isInvalidCertificate(now, hostinfo) {
  288. return closeTunnel, hostinfo, nil
  289. }
  290. primary := cm.hostMap.Hosts[hostinfo.vpnAddrs[0]]
  291. mainHostInfo := true
  292. if primary != nil && primary != hostinfo {
  293. mainHostInfo = false
  294. }
  295. // Check for traffic on this hostinfo
  296. inTraffic, outTraffic := cm.getAndResetTrafficCheck(hostinfo, now)
  297. // A hostinfo is determined alive if there is incoming traffic
  298. if inTraffic {
  299. decision := doNothing
  300. if cm.l.Enabled(context.Background(), slog.LevelDebug) {
  301. hostinfo.logger(cm.l).Debug("Tunnel status",
  302. "tunnelCheck", m{"state": "alive", "method": "passive"},
  303. )
  304. }
  305. hostinfo.pendingDeletion.Store(false)
  306. if mainHostInfo {
  307. decision = tryRehandshake
  308. } else {
  309. if cm.shouldSwapPrimary(hostinfo) {
  310. decision = swapPrimary
  311. } else {
  312. // migrate the relays to the primary, if in use.
  313. decision = migrateRelays
  314. }
  315. }
  316. cm.trafficTimer.Add(hostinfo.localIndexId, cm.checkInterval)
  317. if !outTraffic {
  318. // Send a punch packet to keep the NAT state alive
  319. cm.sendPunch(hostinfo)
  320. }
  321. return decision, hostinfo, primary
  322. }
  323. if hostinfo.pendingDeletion.Load() {
  324. // We have already sent a test packet and nothing was returned, this hostinfo is dead
  325. hostinfo.logger(cm.l).Info("Tunnel status",
  326. "tunnelCheck", m{"state": "dead", "method": "active"},
  327. )
  328. return deleteTunnel, hostinfo, nil
  329. }
  330. decision := doNothing
  331. if hostinfo != nil && hostinfo.ConnectionState != nil && mainHostInfo {
  332. if !outTraffic {
  333. inactiveFor, isInactive := cm.isInactive(hostinfo, now)
  334. if isInactive {
  335. // Tunnel is inactive, tear it down
  336. hostinfo.logger(cm.l).Info("Dropping tunnel due to inactivity",
  337. "inactiveDuration", inactiveFor,
  338. "primary", mainHostInfo,
  339. )
  340. return closeTunnel, hostinfo, primary
  341. }
  342. // If we aren't sending or receiving traffic then its an unused tunnel and we don't to test the tunnel.
  343. // Just maintain NAT state if configured to do so.
  344. cm.sendPunch(hostinfo)
  345. cm.trafficTimer.Add(hostinfo.localIndexId, cm.checkInterval)
  346. return doNothing, nil, nil
  347. }
  348. if cm.punchy.GetTargetEverything() {
  349. // This is similar to the old punchy behavior with a slight optimization.
  350. // We aren't receiving traffic but we are sending it, punch on all known
  351. // ips in case we need to re-prime NAT state
  352. cm.sendPunch(hostinfo)
  353. }
  354. if cm.l.Enabled(context.Background(), slog.LevelDebug) {
  355. hostinfo.logger(cm.l).Debug("Tunnel status",
  356. "tunnelCheck", m{"state": "testing", "method": "active"},
  357. )
  358. }
  359. // Send a test packet to trigger an authenticated tunnel test, this should suss out any lingering tunnel issues
  360. decision = sendTestPacket
  361. } else {
  362. if cm.l.Enabled(context.Background(), slog.LevelDebug) {
  363. hostinfo.logger(cm.l).Debug("Hostinfo sadness")
  364. }
  365. }
  366. hostinfo.pendingDeletion.Store(true)
  367. cm.trafficTimer.Add(hostinfo.localIndexId, cm.pendingDeletionInterval)
  368. return decision, hostinfo, nil
  369. }
  370. func (cm *connectionManager) isInactive(hostinfo *HostInfo, now time.Time) (time.Duration, bool) {
  371. if cm.dropInactive.Load() == false {
  372. // We aren't configured to drop inactive tunnels
  373. return 0, false
  374. }
  375. inactiveDuration := now.Sub(hostinfo.lastUsed)
  376. if inactiveDuration < cm.getInactivityTimeout() {
  377. // It's not considered inactive
  378. return inactiveDuration, false
  379. }
  380. // The tunnel is inactive
  381. return inactiveDuration, true
  382. }
  383. func (cm *connectionManager) shouldSwapPrimary(current *HostInfo) bool {
  384. // The primary tunnel is the most recent handshake to complete locally and should work entirely fine.
  385. // If we are here then we have multiple tunnels for a host pair and neither side believes the same tunnel is primary.
  386. // Let's sort this out.
  387. // Only one side should swap because if both swap then we may never resolve to a single tunnel.
  388. // vpn addr is static across all tunnels for this host pair so lets
  389. // use that to determine if we should consider swapping.
  390. if current.vpnAddrs[0].Compare(cm.intf.myVpnAddrs[0]) < 0 {
  391. // Their primary vpn addr is less than mine. Do not swap.
  392. return false
  393. }
  394. crt := cm.intf.pki.getCertState().getCertificate(current.ConnectionState.myCert.Version())
  395. if crt == nil {
  396. //my cert was reloaded away. We should definitely swap from this tunnel
  397. return true
  398. }
  399. // If this tunnel is using the latest certificate then we should swap it to primary for a bit and see if things
  400. // settle down.
  401. return bytes.Equal(current.ConnectionState.myCert.Signature(), crt.Signature())
  402. }
  403. func (cm *connectionManager) swapPrimary(current, primary *HostInfo) {
  404. cm.hostMap.Lock()
  405. // Make sure the primary is still the same after the write lock. This avoids a race with a rehandshake.
  406. if cm.hostMap.Hosts[current.vpnAddrs[0]] == primary {
  407. cm.hostMap.unlockedMakePrimary(current)
  408. }
  409. cm.hostMap.Unlock()
  410. }
  411. // isInvalidCertificate decides if we should destroy a tunnel.
  412. // returns true if pki.disconnect_invalid is true and the certificate is no longer valid.
  413. // Blocklisted certificates will skip the pki.disconnect_invalid check and return true.
  414. func (cm *connectionManager) isInvalidCertificate(now time.Time, hostinfo *HostInfo) bool {
  415. remoteCert := hostinfo.GetCert()
  416. if remoteCert == nil {
  417. return false //don't tear down tunnels for handshakes in progress
  418. }
  419. caPool := cm.intf.pki.GetCAPool()
  420. err := caPool.VerifyCachedCertificate(now, remoteCert)
  421. if err == nil {
  422. return false //cert is still valid! yay!
  423. } else if err == cert.ErrBlockListed { //avoiding errors.Is for speed
  424. // Block listed certificates should always be disconnected
  425. hostinfo.logger(cm.l).Info("Remote certificate is blocked, tearing down the tunnel",
  426. "error", err,
  427. "fingerprint", remoteCert.Fingerprint,
  428. )
  429. return true
  430. } else if cm.intf.disconnectInvalid.Load() {
  431. hostinfo.logger(cm.l).Info("Remote certificate is no longer valid, tearing down the tunnel",
  432. "error", err,
  433. "fingerprint", remoteCert.Fingerprint,
  434. )
  435. return true
  436. } else {
  437. //if we reach here, the cert is no longer valid, but we're configured to keep tunnels from now-invalid certs open
  438. return false
  439. }
  440. }
  441. func (cm *connectionManager) sendPunch(hostinfo *HostInfo) {
  442. if !cm.punchy.GetPunch() {
  443. // Punching is disabled
  444. return
  445. }
  446. if cm.intf.lightHouse.IsAnyLighthouseAddr(hostinfo.vpnAddrs) {
  447. // Do not punch to lighthouses, we assume our lighthouse update interval is good enough.
  448. // In the event the update interval is not sufficient to maintain NAT state then a publicly available lighthouse
  449. // would lose the ability to notify us and punchy.respond would become unreliable.
  450. return
  451. }
  452. if cm.punchy.GetTargetEverything() {
  453. hostinfo.remotes.ForEach(cm.hostMap.GetPreferredRanges(), func(addr netip.AddrPort, preferred bool) {
  454. cm.metricsTxPunchy.Inc(1)
  455. cm.intf.outside.WriteTo([]byte{1}, addr)
  456. })
  457. } else if hostinfo.remote.IsValid() {
  458. cm.metricsTxPunchy.Inc(1)
  459. cm.intf.outside.WriteTo([]byte{1}, hostinfo.remote)
  460. }
  461. }
  462. func (cm *connectionManager) tryRehandshake(hostinfo *HostInfo) {
  463. cs := cm.intf.pki.getCertState()
  464. curCrt := hostinfo.ConnectionState.myCert
  465. curCrtVersion := curCrt.Version()
  466. myCrt := cs.getCertificate(curCrtVersion)
  467. if myCrt == nil {
  468. cm.l.Info("Re-handshaking with remote",
  469. "vpnAddrs", hostinfo.vpnAddrs,
  470. "version", curCrtVersion,
  471. "reason", "local certificate removed",
  472. )
  473. cm.intf.handshakeManager.StartHandshake(hostinfo.vpnAddrs[0], nil)
  474. return
  475. }
  476. peerCrt := hostinfo.ConnectionState.peerCert
  477. if peerCrt != nil && curCrtVersion < peerCrt.Certificate.Version() {
  478. // if our certificate version is less than theirs, and we have a matching version available, rehandshake?
  479. if cs.getCertificate(peerCrt.Certificate.Version()) != nil {
  480. cm.l.Info("Re-handshaking with remote",
  481. "vpnAddrs", hostinfo.vpnAddrs,
  482. "version", curCrtVersion,
  483. "peerVersion", peerCrt.Certificate.Version(),
  484. "reason", "local certificate version lower than peer, attempting to correct",
  485. )
  486. cm.intf.handshakeManager.StartHandshake(hostinfo.vpnAddrs[0], func(hh *HandshakeHostInfo) {
  487. hh.initiatingVersionOverride = peerCrt.Certificate.Version()
  488. })
  489. return
  490. }
  491. }
  492. if !bytes.Equal(curCrt.Signature(), myCrt.Signature()) {
  493. cm.l.Info("Re-handshaking with remote",
  494. "vpnAddrs", hostinfo.vpnAddrs,
  495. "reason", "local certificate is not current",
  496. )
  497. cm.intf.handshakeManager.StartHandshake(hostinfo.vpnAddrs[0], nil)
  498. return
  499. }
  500. if curCrtVersion < cs.initiatingVersion {
  501. cm.l.Info("Re-handshaking with remote",
  502. "vpnAddrs", hostinfo.vpnAddrs,
  503. "reason", "current cert version < pki.initiatingVersion",
  504. )
  505. cm.intf.handshakeManager.StartHandshake(hostinfo.vpnAddrs[0], nil)
  506. return
  507. }
  508. }