interface_openbsd.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package route
  5. func (*wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) {
  6. if len(b) < 32 {
  7. return nil, errMessageTooShort
  8. }
  9. l := int(nativeEndian.Uint16(b[:2]))
  10. if len(b) < l {
  11. return nil, errInvalidMessage
  12. }
  13. attrs := uint(nativeEndian.Uint32(b[12:16]))
  14. if attrs&sysRTA_IFP == 0 {
  15. return nil, nil
  16. }
  17. m := &InterfaceMessage{
  18. Version: int(b[2]),
  19. Type: int(b[3]),
  20. Flags: int(nativeEndian.Uint32(b[16:20])),
  21. Index: int(nativeEndian.Uint16(b[6:8])),
  22. Addrs: make([]Addr, sysRTAX_MAX),
  23. raw: b[:l],
  24. }
  25. ll := int(nativeEndian.Uint16(b[4:6]))
  26. if len(b) < ll {
  27. return nil, errInvalidMessage
  28. }
  29. a, err := parseLinkAddr(b[ll:])
  30. if err != nil {
  31. return nil, err
  32. }
  33. m.Addrs[sysRTAX_IFP] = a
  34. m.Name = a.(*LinkAddr).Name
  35. return m, nil
  36. }
  37. func (*wireFormat) parseInterfaceAddrMessage(_ RIBType, b []byte) (Message, error) {
  38. if len(b) < 24 {
  39. return nil, errMessageTooShort
  40. }
  41. l := int(nativeEndian.Uint16(b[:2]))
  42. if len(b) < l {
  43. return nil, errInvalidMessage
  44. }
  45. bodyOff := int(nativeEndian.Uint16(b[4:6]))
  46. if len(b) < bodyOff {
  47. return nil, errInvalidMessage
  48. }
  49. m := &InterfaceAddrMessage{
  50. Version: int(b[2]),
  51. Type: int(b[3]),
  52. Flags: int(nativeEndian.Uint32(b[12:16])),
  53. Index: int(nativeEndian.Uint16(b[6:8])),
  54. raw: b[:l],
  55. }
  56. var err error
  57. m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[12:16])), parseKernelInetAddr, b[bodyOff:])
  58. if err != nil {
  59. return nil, err
  60. }
  61. return m, nil
  62. }
  63. func (*wireFormat) parseInterfaceAnnounceMessage(_ RIBType, b []byte) (Message, error) {
  64. if len(b) < 26 {
  65. return nil, errMessageTooShort
  66. }
  67. l := int(nativeEndian.Uint16(b[:2]))
  68. if len(b) < l {
  69. return nil, errInvalidMessage
  70. }
  71. m := &InterfaceAnnounceMessage{
  72. Version: int(b[2]),
  73. Type: int(b[3]),
  74. Index: int(nativeEndian.Uint16(b[6:8])),
  75. What: int(nativeEndian.Uint16(b[8:10])),
  76. raw: b[:l],
  77. }
  78. for i := 0; i < 16; i++ {
  79. if b[10+i] != 0 {
  80. continue
  81. }
  82. m.Name = string(b[10 : 10+i])
  83. break
  84. }
  85. return m, nil
  86. }