-
Notifications
You must be signed in to change notification settings - Fork 24
Prefix Insertion Support in dv #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jaczhi
wants to merge
37
commits into
named-data:main
Choose a base branch
from
jaczhi:jaczhi/prefix-inject
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 25 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
9452847
initial skeleton of core logic
jaczhi b46d76a
add parsing and validation
jaczhi 93f16c8
also add into local forwarder
jaczhi a40255e
Merge branch 'main' into jaczhi/prefix-inject
jaczhi 21cc8e8
custom fetch
jaczhi c4de196
use stapled certificates
jaczhi ca0299e
fix command name to not use keyword component
jaczhi 5974548
remember to reply to prefix injection
jaczhi 7b3e6fc
fix usage of wrong api for prefix table
jaczhi ecb70b0
fix trust anchor typo
jaczhi 6c1dc20
stapled certs are non-critical
jaczhi d9e04f9
regenerate
jaczhi f343014
change parse order
jaczhi 1fbc450
revert
jaczhi 5164c88
defer doesn't work with callbacks
jaczhi c62b4af
prefix injection remove
jaczhi 40a36c6
avoid redundant parsing
jaczhi 613c6b8
change default behavior for backwards compatibility
jaczhi fb597e9
Merge branch 'main' into jaczhi/prefix-inject
jaczhi 417fb6c
remove negative cases for uint
jaczhi 36ff0ec
fix import order for lint
jaczhi 541d50c
refactor control command response, use binary fields, move defs to dv
jaczhi 1333688
Merge branch 'main' into jaczhi/prefix-inject
zjkmxy e73f881
Merge branch 'main' into jaczhi/prefix-inject
jaczhi 3d3dcf6
Merge branch 'jaczhi/prefix-inject' of https://github.com/jaczhi/ndnd…
jaczhi 8240215
update constants and format to comply with new protocol format
jaczhi 811015f
fix pa object name parsing
jaczhi 984aeff
generate
jaczhi eaa1cd7
reject seen PA
jaczhi 2aced71
check validityperiod
jaczhi 2af277e
rename injection to insertion
jaczhi 87f2840
use time format constant from spec
jaczhi 803ef78
rename TLV inside PrefixInsertion to proper name
jaczhi 042921d
do not construct prefix injection client if prefix injection is disabled
jaczhi 28995d8
reduce collision by using binary string for hashing
jaczhi 4b2447d
revert unncessary start logic
jaczhi c31911a
Merge branch 'main' into jaczhi/prefix-inject
zjkmxy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
package dv | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/named-data/ndnd/dv/config" | ||
"github.com/named-data/ndnd/dv/nfdc" | ||
"github.com/named-data/ndnd/dv/tlv" | ||
enc "github.com/named-data/ndnd/std/encoding" | ||
"github.com/named-data/ndnd/std/log" | ||
"github.com/named-data/ndnd/std/ndn" | ||
mgmt "github.com/named-data/ndnd/std/ndn/mgmt_2022" | ||
spec "github.com/named-data/ndnd/std/ndn/spec_2022" | ||
sig "github.com/named-data/ndnd/std/security/signer" | ||
"github.com/named-data/ndnd/std/types/optional" | ||
) | ||
|
||
func (dv *Router) onInjection(args ndn.InterestHandlerArgs) { | ||
resError := &mgmt.ControlResponse{ | ||
Val: &mgmt.ControlResponseVal{ | ||
StatusCode: 400, | ||
StatusText: "Failed to execute prefix injection", | ||
Params: nil, | ||
}, | ||
} | ||
|
||
reply := func(res *mgmt.ControlResponse) { | ||
signer := sig.NewSha256Signer() | ||
data, err := dv.engine.Spec().MakeData( | ||
args.Interest.Name(), | ||
&ndn.DataConfig{ | ||
ContentType: optional.Some(ndn.ContentTypeBlob), | ||
Freshness: optional.Some(1 * time.Second), | ||
}, | ||
res.Encode(), | ||
signer) | ||
if err != nil { | ||
log.Warn(dv, "Failed to make inject response Data", "err", err) | ||
return | ||
} | ||
args.Reply(data.Wire) | ||
} | ||
|
||
// If there is no incoming face ID, we can't use this | ||
if !args.IncomingFaceId.IsSet() { | ||
log.Warn(dv, "Received Prefix Injection with no incoming face ID, ignoring") | ||
reply(resError) | ||
return | ||
} | ||
|
||
// Check if app param is present | ||
if args.Interest.AppParam() == nil { | ||
log.Warn(dv, "Received Prefix Injection with no AppParam, ignoring") | ||
reply(resError) | ||
return | ||
} | ||
|
||
paParams, err := tlv.ParsePrefixInjection(enc.NewWireView(args.Interest.AppParam()), true) | ||
if err != nil { | ||
log.Warn(dv, "Failed to parse Prefix Injection AppParam", "err", err) | ||
reply(resError) | ||
return | ||
} | ||
|
||
// Decode Prefix Injection Object | ||
dCtx := spec.DataParsingContext{} | ||
dCtx.Init() | ||
data, err := dCtx.Parse(enc.NewBufferView(paParams.ObjectWire), true) | ||
if err != nil { | ||
log.Warn(dv, "Failed to parse Prefix Injection inner data", "err", err) | ||
reply(resError) | ||
return | ||
} | ||
sigCov := dCtx.SigCovered() | ||
|
||
var stapledCertCallbacks []ndn.ExpressCallbackArgs | ||
for _, certWire := range paParams.StapledCertificates { | ||
data, sigCov, err := spec.Spec{}.ReadData(enc.NewBufferView(certWire)) | ||
if err != nil { | ||
log.Warn(dv, "Stapled malformed certificate", "err", err) | ||
reply(resError) | ||
return | ||
} | ||
|
||
stapledCertCallbacks = append(stapledCertCallbacks, | ||
ndn.ExpressCallbackArgs{ | ||
Result: ndn.InterestResultData, | ||
Data: data, | ||
RawData: enc.Wire{certWire}, | ||
SigCovered: sigCov, | ||
IsLocal: true, | ||
}) | ||
} | ||
|
||
// Validate signature | ||
dv.prefixInjectionClient.ValidateExt(ndn.ValidateExtArgs{ | ||
Data: data, | ||
SigCovered: sigCov, | ||
Fetch: optional.Some(func(name enc.Name, config *ndn.InterestConfig, callback ndn.ExpressCallbackFunc) { | ||
for _, certCallback := range stapledCertCallbacks { | ||
if certCallback.Data.Name().Equal(name) { | ||
dv.prefixInjectionClient.Engine().Post(func() { | ||
callback(certCallback) | ||
}) | ||
return | ||
} | ||
} | ||
|
||
config.NextHopId = optional.None[uint64]() | ||
dv.prefixInjectionClient.ExpressR(ndn.ExpressRArgs{ | ||
Name: name, | ||
Config: config, | ||
Retries: 3, | ||
Callback: callback, | ||
TryStore: dv.prefixInjectionClient.Store(), | ||
}) | ||
}), | ||
Callback: func(valid bool, err error) { | ||
if !valid || err != nil { | ||
log.Warn(dv, "Failed to validate signature", "name", data.Name(), "valid", valid, "err", err) | ||
reply(resError) | ||
return | ||
} | ||
|
||
res := dv.onPrefixInjectionObject(data, args.IncomingFaceId.Unwrap()) | ||
reply(res) | ||
}, | ||
}) | ||
} | ||
|
||
func (dv *Router) onPrefixInjectionObject(object ndn.Data, faceId uint64) *mgmt.ControlResponse { | ||
resError := &mgmt.ControlResponse{ | ||
Val: &mgmt.ControlResponseVal{ | ||
StatusCode: 400, | ||
StatusText: "Failed to execute prefix injection", | ||
Params: nil, | ||
}, | ||
} | ||
|
||
if contentType, set := object.ContentType().Get(); !set || contentType != ndn.ContentTypePrefixInjection { | ||
log.Warn(dv, "Prefix Injection Object does not have the correct content type", | ||
"contentType", object.ContentType()) | ||
return resError | ||
} | ||
|
||
// TODO: reject already seen injections (using version) | ||
var prefix enc.Name | ||
found := false | ||
|
||
for i, c := range object.Name() { | ||
if c.IsKeyword("inject") { | ||
prefix = object.Name().Prefix(i) | ||
found = true | ||
break | ||
} | ||
} | ||
|
||
if !found { | ||
log.Warn(dv, "Prefix Injection Object name not in correct format", "name", object.Name()) | ||
return resError | ||
} | ||
|
||
piWire := object.Content() | ||
params, err := tlv.ParsePrefixInjectionInnerContent(enc.NewWireView(piWire), true) | ||
if err != nil { | ||
log.Warn(dv, "Failed to parse prefix injection object", "err", err) | ||
return resError | ||
} | ||
|
||
var shouldRemove bool | ||
var cost uint64 | ||
if params.ExpirationPeriod == 0 { | ||
// Remove the RIB entry | ||
shouldRemove = true | ||
cost = config.CostInfinity | ||
} else { | ||
// Add or update RIB entry | ||
shouldRemove = false | ||
cost = params.Cost.GetOr(0) | ||
if cost > config.CostInfinity { | ||
log.Warn(dv, "Invalid Cost value", "Cost", cost) | ||
return resError | ||
} | ||
} | ||
|
||
if shouldRemove { | ||
dv.nfdc.Exec(nfdc.NfdMgmtCmd{ | ||
Module: "rib", | ||
Cmd: "unregister", | ||
Args: &mgmt.ControlArgs{ | ||
Name: prefix, | ||
FaceId: optional.Some(faceId), | ||
}, | ||
Retries: 3, | ||
}) | ||
} else { | ||
dv.nfdc.Exec(nfdc.NfdMgmtCmd{ | ||
Module: "rib", | ||
Cmd: "register", | ||
Args: &mgmt.ControlArgs{ | ||
Name: prefix, | ||
FaceId: optional.Some(faceId), | ||
Origin: optional.Some(config.PrefixInjOrigin), | ||
Cost: optional.Some(cost), | ||
}, | ||
Retries: 3, | ||
}) | ||
} | ||
|
||
dv.mutex.Lock() | ||
defer dv.mutex.Unlock() | ||
|
||
if shouldRemove { | ||
dv.pfx.Withdraw(prefix, faceId) | ||
} else { | ||
dv.pfx.Announce(prefix, faceId, cost) | ||
} | ||
|
||
return &mgmt.ControlResponse{ | ||
Val: &mgmt.ControlResponseVal{ | ||
StatusCode: 200, | ||
StatusText: "Prefix Injection command successful", | ||
Params: &mgmt.ControlArgs{ | ||
Name: prefix, | ||
FaceId: optional.Some(faceId), | ||
Origin: optional.Some(config.PrefixInjOrigin), | ||
Cost: optional.Some(cost), | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A concrete example of the trust schema should be included as part of the repository.