Skip to content

Commit 6b4af40

Browse files
committed
feat: implement SOL (Serial Over LAN) payload functionality
- Added SOL payload request and response types to support SOL communication. - Introduced SOLActivate method for activating SOL payload sessions. - Enhanced UDP client with ExchangeUntilMatch for filtering responses.
1 parent cff9554 commit 6b4af40

16 files changed

+787
-79
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ cmd/goipmi/goipmi
4444

4545
# asdf
4646
.tool-versions
47+
goipmi

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ The implementation logic of IPMI commands is largely consistent. See [Contributi
328328
| GetUserCallbackOptions | | |
329329
| SetSerialRoutingMux | | |
330330
| SOLActivating | :white_check_mark: | |
331+
| SOLActivate (\*) | :white_check_mark: | sol activate |
331332
| SetSOLConfigParam | :white_check_mark: | |
332333
| SetSOLConfigParamFor (\*) | :white_check_mark: | |
333334
| GetSOLConfigParam | :white_check_mark: | |

client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ func (c *Client) Close(ctx context.Context) error {
265265
}
266266

267267
func (c *Client) Exchange(ctx context.Context, request Request, response Response) error {
268+
if c.Interface != InterfaceLanplus {
269+
if _, ok := request.(*SOLPayloadRequest); ok {
270+
return fmt.Errorf("SOL payload exchange requires lanplus interface")
271+
}
272+
}
273+
268274
switch c.Interface {
269275
case "", InterfaceOpen:
270276
return c.exchangeOpen(ctx, request, response)

cmd/goipmi/commands/sol.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package commands
33
import (
44
"context"
55
"fmt"
6+
"os"
67

8+
"github.com/bougou/go-ipmi"
79
"github.com/spf13/cobra"
810
)
911

@@ -21,6 +23,7 @@ func NewCmdSOL() *cobra.Command {
2123
},
2224
}
2325
cmd.AddCommand(NewCmdSOLInfo())
26+
cmd.AddCommand(NewCmdSOLActivate())
2427

2528
return cmd
2629
}
@@ -40,3 +43,40 @@ func NewCmdSOLInfo() *cobra.Command {
4043
}
4144
return cmd
4245
}
46+
47+
func NewCmdSOLActivate() *cobra.Command {
48+
usage := `
49+
activate [<payload instance>]
50+
`
51+
52+
cmd := &cobra.Command{
53+
Use: "activate",
54+
Short: "activate SOL payload",
55+
Run: func(cmd *cobra.Command, args []string) {
56+
payloadInstance := uint8(1)
57+
if len(args) >= 1 {
58+
id, err := parseStringToInt64(args[0])
59+
if err != nil {
60+
CheckErr(fmt.Errorf("invalid payload instance, err: %w", err))
61+
}
62+
if id < 0 || id > 0x3f {
63+
CheckErr(fmt.Errorf("invalid payload instance, usage: %s", usage))
64+
}
65+
payloadInstance = uint8(id)
66+
}
67+
68+
ctx := context.Background()
69+
var opts *ipmi.SOLActivateOptions
70+
if payloadInstance != 1 {
71+
opts = &ipmi.SOLActivateOptions{
72+
PayloadInstance: payloadInstance,
73+
}
74+
}
75+
76+
if err := client.SOLActivate(ctx, os.Stdin, os.Stdout, opts); err != nil {
77+
CheckErr(err)
78+
}
79+
},
80+
}
81+
return cmd
82+
}

cmd_activate_session.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func (c *Client) ActivateSession(ctx context.Context) (response *ActivateSession
149149
// Todo, validate the SessionID
150150
c.session.v15.sessionID = response.SessionID
151151

152+
// Authentication type for the remainder of the session (response data[0]). When per-message
153+
// authentication is disabled, BMCs typically return NONE here even though challenge/activate
154+
// used MD5; subsequent RMCP session headers must match this (see ipmitool with Per-msg auth off).
155+
c.session.authType = response.AuthType
156+
152157
// The remote console must increment the inbound session sequence number
153158
// by one (1) for each subsequent message it sends to the BMC
154159
c.session.v15.inSeq = response.InitialInboundSequenceNumber

0 commit comments

Comments
 (0)