mpc = mpcs; /* our global linked list */ while (mpc != NULL) { if (mpc->dev == dev) return mpc;
mpc = mpc->next;
}
return NULL; /* not found */
}
/* * Functions for managing QoS list
*/
/* * Overwrites the old entry or makes a new one.
*/ struct atm_mpoa_qos *atm_mpoa_add_qos(__be32 dst_ip, struct atm_qos *qos)
{ struct atm_mpoa_qos *entry;
/* * * start_mpc() puts the MPC on line. All the packets destined * to the lec underneath us are now being monitored and * shortcuts will be established. *
*/ staticvoid start_mpc(struct mpoa_client *mpc, struct net_device *dev)
{
staticconstchar *mpoa_device_type_string(char type)
{ switch (type) { case NON_MPOA: return"non-MPOA device"; case MPS: return"MPS"; case MPC: return"MPC"; case MPS_AND_MPC: return"both MPS and MPC";
}
return"unspecified (non-MPOA) device";
}
/* * lec device calls this via its netdev_priv(dev)->lane2_ops * ->associate_indicator() when it sees a TLV in LE_ARP packet. * We fill in the pointer above when we see a LANE2 lec initializing * See LANE2 spec 3.1.5 * * Quite a big and ugly function but when you look at it * all it does is to try to locate and parse MPOA Device * Type TLV. * We give our lec a pointer to this function and when the * lec sees a TLV it uses the pointer to call this function. *
*/ staticvoid lane2_assoc_ind(struct net_device *dev, const u8 *mac_addr, const u8 *tlvs, u32 sizeoftlvs)
{
uint32_t type;
uint8_t length, mpoa_device_type, number_of_mps_macs; const uint8_t *end_of_tlvs; struct mpoa_client *mpc;
mpoa_device_type = number_of_mps_macs = 0; /* silence gcc */
dprintk("(%s) received TLV(s), ", dev->name);
dprintk("total length of all TLVs %d\n", sizeoftlvs);
mpc = find_mpc_by_lec(dev); /* Sampo-Fix: moved here from below */ if (mpc == NULL) {
pr_info("(%s) no mpc\n", dev->name); return;
}
end_of_tlvs = tlvs + sizeoftlvs; while (end_of_tlvs - tlvs >= 5) {
type = ((tlvs[0] << 24) | (tlvs[1] << 16) |
(tlvs[2] << 8) | tlvs[3]);
length = tlvs[4];
tlvs += 5;
dprintk(" type 0x%x length %02x\n", type, length); if (tlvs + length > end_of_tlvs) {
pr_info("TLV value extends past its buffer, aborting parse\n"); return;
}
if (type == 0) {
pr_info("mpoa: (%s) TLV type was 0, returning\n",
dev->name); return;
}
if (type != TLV_MPOA_DEVICE_TYPE) {
tlvs += length; continue; /* skip other TLVs */
}
mpoa_device_type = *tlvs++;
number_of_mps_macs = *tlvs++;
dprintk("(%s) MPOA device type '%s', ",
dev->name, mpoa_device_type_string(mpoa_device_type)); if (mpoa_device_type == MPS_AND_MPC &&
length < (42 + number_of_mps_macs*ETH_ALEN)) { /* :) */
pr_info("(%s) short MPOA Device Type TLV\n",
dev->name); continue;
} if ((mpoa_device_type == MPS || mpoa_device_type == MPC) &&
length < 22 + number_of_mps_macs*ETH_ALEN) {
pr_info("(%s) short MPOA Device Type TLV\n", dev->name); continue;
} if (mpoa_device_type != MPS &&
mpoa_device_type != MPS_AND_MPC) {
dprintk("ignoring non-MPS device "); if (mpoa_device_type == MPC)
tlvs += 20; continue; /* we are only interested in MPSs */
} if (number_of_mps_macs == 0 &&
mpoa_device_type == MPS_AND_MPC) {
pr_info("(%s) MPS_AND_MPC has zero MACs\n", dev->name); continue; /* someone should read the spec */
}
dprintk_cont("this MPS has %d MAC addresses\n",
number_of_mps_macs);
/* * ok, now we can go and tell our daemon * the control address of MPS
*/
send_set_mps_ctrl_addr(tlvs, mpc);
/* * Store at least advertizing router's MAC address * plus the possible MAC address(es) to mpc->mps_macs. * For a freshly allocated MPOA client mpc->mps_macs == 0.
*/ staticconst uint8_t *copy_macs(struct mpoa_client *mpc, const uint8_t *router_mac, const uint8_t *tlvs, uint8_t mps_macs,
uint8_t device_type)
{ int num_macs;
num_macs = (mps_macs > 1) ? mps_macs : 1;
if (mpc->number_of_mps_macs != num_macs) { /* need to reallocate? */ if (mpc->number_of_mps_macs != 0)
kfree(mpc->mps_macs);
mpc->number_of_mps_macs = 0;
mpc->mps_macs = kmalloc_array(ETH_ALEN, num_macs, GFP_KERNEL); if (mpc->mps_macs == NULL) {
pr_info("(%s) out of mem\n", mpc->dev->name); return NULL;
}
}
ether_addr_copy(mpc->mps_macs, router_mac);
tlvs += 20; if (device_type == MPS_AND_MPC) tlvs += 20; if (mps_macs > 0)
memcpy(mpc->mps_macs, tlvs, mps_macs*ETH_ALEN);
tlvs += mps_macs*ETH_ALEN;
mpc->number_of_mps_macs = num_macs;
entry = mpc->in_ops->get(ipaddr, mpc); if (entry == NULL) {
entry = mpc->in_ops->add_entry(ipaddr, mpc); if (entry != NULL)
mpc->in_ops->put(entry); return 1;
} /* threshold not exceeded or VCC not ready */ if (mpc->in_ops->cache_hit(entry, mpc) != OPEN) {
ddprintk("(%s) cache_hit: returns != OPEN\n",
mpc->dev->name);
mpc->in_ops->put(entry); return 1;
}
ddprintk("(%s) using shortcut\n",
mpc->dev->name); /* MPOA spec A.1.4, MPOA client must decrement IP ttl at least by one */ if (iph->ttl <= 1) {
ddprintk("(%s) IP ttl = %u, using LANE\n",
mpc->dev->name, iph->ttl);
mpc->in_ops->put(entry); return 1;
}
iph->ttl--;
iph->check = 0;
iph->check = ip_fast_csum((unsignedchar *)iph, iph->ihl);
if (entry->ctrl_info.tag != 0) {
ddprintk("(%s) adding tag 0x%x\n",
mpc->dev->name, entry->ctrl_info.tag);
tagged_llc_snap_hdr.tag = entry->ctrl_info.tag;
skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
skb_push(skb, sizeof(tagged_llc_snap_hdr)); /* add LLC/SNAP header */
skb_copy_to_linear_data(skb, &tagged_llc_snap_hdr, sizeof(tagged_llc_snap_hdr));
} else {
skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
skb_push(skb, sizeof(struct llc_snap_hdr)); /* add LLC/SNAP header + tag */
skb_copy_to_linear_data(skb, &llc_snap_mpoa_data, sizeof(struct llc_snap_hdr));
}
/* * Probably needs some error checks and locking, not sure...
*/ static netdev_tx_t mpc_send_packet(struct sk_buff *skb, struct net_device *dev)
{ struct mpoa_client *mpc; struct ethhdr *eth; int i = 0;
mpc = find_mpc_by_lec(dev); /* this should NEVER fail */ if (mpc == NULL) {
pr_info("(%s) no MPC found\n", dev->name); goto non_ip;
}
eth = (struct ethhdr *)skb->data; if (eth->h_proto != htons(ETH_P_IP)) goto non_ip; /* Multi-Protocol Over ATM :-) */
/* Weed out funny packets (e.g., AF_PACKET or raw). */ if (skb->len < ETH_HLEN + sizeof(struct iphdr)) goto non_ip;
skb_set_network_header(skb, ETH_HLEN); if (skb->len < ETH_HLEN + ip_hdr(skb)->ihl * 4 || ip_hdr(skb)->ihl < 5) goto non_ip;
while (i < mpc->number_of_mps_macs) { if (ether_addr_equal(eth->h_dest, mpc->mps_macs + i * ETH_ALEN)) if (send_via_shortcut(skb, mpc) == 0) /* try shortcut */ return NETDEV_TX_OK;
i++;
}
/* * See if ingress MPC is using shortcut we opened as a return channel. * This means we have a bi-directional vcc opened by us.
*/ if (eg->shortcut == NULL) {
eg->shortcut = vcc;
pr_info("(%s) egress SVC in use\n", dev->name);
}
skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag)); /* get rid of LLC/SNAP header */
new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length); /* LLC/SNAP is shorter than MAC header :( */
dev_kfree_skb_any(skb); if (new_skb == NULL) {
mpc->eg_ops->put(eg); return;
}
skb_push(new_skb, eg->ctrl_info.DH_length); /* add MAC header */
skb_copy_to_linear_data(new_skb, eg->ctrl_info.DLL_header,
eg->ctrl_info.DH_length);
new_skb->protocol = eth_type_trans(new_skb, dev);
skb_reset_network_header(new_skb);
staticconststruct atmdev_ops mpc_ops = { /* only send is required */
.close = mpoad_close,
.send = msg_from_mpoad
};
staticstruct atm_dev mpc_dev = {
.ops = &mpc_ops,
.type = "mpc",
.number = 42,
.lock = __SPIN_LOCK_UNLOCKED(mpc_dev.lock) /* members not explicitly initialised will be 0 */
};
staticint atm_mpoa_mpoad_attach(struct atm_vcc *vcc, int arg)
{ struct mpoa_client *mpc; struct lec_priv *priv; int err;
if (mpcs == NULL) {
mpc_timer_refresh();
/* This lets us now how our LECs are doing */
err = register_netdevice_notifier(&mpoa_notifier); if (err < 0) {
timer_delete(&mpc_timer); return err;
}
}
mpc = find_mpc_by_itfnum(arg); if (mpc == NULL) {
dprintk("allocating new mpc for itf %d\n", arg);
mpc = alloc_mpc(); if (mpc == NULL) return -ENOMEM;
mpc->dev_num = arg;
mpc->dev = find_lec_by_itfnum(arg); /* NULL if there was no lec */
} if (mpc->mpoad_vcc) {
pr_info("mpoad is already present for itf %d\n", arg); return -EADDRINUSE;
}
if (mpc->dev) { /* check if the lec is LANE2 capable */
priv = netdev_priv(mpc->dev); if (priv->lane_version < 2) {
dev_put(mpc->dev);
mpc->dev = NULL;
} else
priv->lane2_ops->associate_indicator = lane2_assoc_ind;
}
if (mpc->dev) { char empty[ATM_ESA_LEN];
memset(empty, 0, ATM_ESA_LEN);
start_mpc(mpc, mpc->dev); /* set address if mpcd e.g. gets killed and restarted. * If we do not do it now we have to wait for the next LE_ARP
*/ if (memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0)
send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc);
}
if (mpc == NULL) {
pr_info("no mpc found\n"); return 0;
}
dprintk("(%s)", mpc->dev ? mpc->dev->name : ""); switch (mesg->type) { case MPOA_RES_REPLY_RCVD:
dprintk_cont("mpoa_res_reply_rcvd\n");
MPOA_res_reply_rcvd(mesg, mpc); break; case MPOA_TRIGGER_RCVD:
dprintk_cont("mpoa_trigger_rcvd\n");
MPOA_trigger_rcvd(mesg, mpc); break; case INGRESS_PURGE_RCVD:
dprintk_cont("nhrp_purge_rcvd\n");
ingress_purge_rcvd(mesg, mpc); break; case EGRESS_PURGE_RCVD:
dprintk_cont("egress_purge_reply_rcvd\n");
egress_purge_rcvd(mesg, mpc); break; case MPS_DEATH:
dprintk_cont("mps_death\n");
mps_death(mesg, mpc); break; case CACHE_IMPOS_RCVD:
dprintk_cont("cache_impos_rcvd\n");
MPOA_cache_impos_rcvd(mesg, mpc); break; case SET_MPC_CTRL_ADDR:
dprintk_cont("set_mpc_ctrl_addr\n");
set_mpc_ctrl_addr_rcvd(mesg, mpc); break; case SET_MPS_MAC_ADDR:
dprintk_cont("set_mps_mac_addr\n");
set_mps_mac_addr_rcvd(mesg, mpc); break; case CLEAN_UP_AND_EXIT:
dprintk_cont("clean_up_and_exit\n");
clean_up(mesg, mpc, DIE); break; case RELOAD:
dprintk_cont("reload\n");
clean_up(mesg, mpc, RELOAD); break; case SET_MPC_PARAMS:
dprintk_cont("set_mpc_params\n");
mpc->parameters = mesg->content.params; break; default:
dprintk_cont("unknown message %d\n", mesg->type); break;
}
kfree_skb(skb);
return 0;
}
/* Remember that this function may not do things that sleep */ int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc)
{ struct sk_buff *skb; struct sock *sk;
if (mpc == NULL || !mpc->mpoad_vcc) {
pr_info("mesg %d to a non-existent mpoad\n", mesg->type); return -ENXIO;
}
if (!net_eq(dev_net(dev), &init_net)) return NOTIFY_DONE;
if (strncmp(dev->name, "lec", 3)) return NOTIFY_DONE; /* we are only interested in lec:s */
switch (event) { case NETDEV_REGISTER: /* a new lec device was allocated */
priv = netdev_priv(dev); if (priv->lane_version < 2) break;
priv->lane2_ops->associate_indicator = lane2_assoc_ind;
mpc = find_mpc_by_itfnum(priv->itfnum); if (mpc == NULL) {
dprintk("allocating new mpc for %s\n", dev->name);
mpc = alloc_mpc(); if (mpc == NULL) {
pr_info("no new mpc"); break;
}
}
mpc->dev_num = priv->itfnum;
mpc->dev = dev;
dev_hold(dev);
dprintk("(%s) was initialized\n", dev->name); break; case NETDEV_UNREGISTER: /* the lec device was deallocated */
mpc = find_mpc_by_lec(dev); if (mpc == NULL) break;
dprintk("device (%s) was deallocated\n", dev->name);
stop_mpc(mpc);
dev_put(mpc->dev);
mpc->dev = NULL; break; case NETDEV_UP: /* the dev was ifconfig'ed up */
mpc = find_mpc_by_lec(dev); if (mpc == NULL) break; if (mpc->mpoad_vcc != NULL)
start_mpc(mpc, dev); break; case NETDEV_DOWN: /* the dev was ifconfig'ed down */ /* this means that the flow of packets from the * upper layer stops
*/
mpc = find_mpc_by_lec(dev); if (mpc == NULL) break; if (mpc->mpoad_vcc != NULL)
stop_mpc(mpc); break; case NETDEV_REBOOT: case NETDEV_CHANGE: case NETDEV_CHANGEMTU: case NETDEV_CHANGEADDR: case NETDEV_GOING_DOWN: break; default: break;
}
return NOTIFY_DONE;
}
/* * Functions which are called after a message is received from mpcd. * Msg is reused on purpose.
*/
/* * Things get complicated because we have to check if there's an egress * shortcut with suitable traffic parameters we could use.
*/ staticvoid check_qos_and_open_shortcut(struct k_message *msg, struct mpoa_client *client,
in_cache_entry *entry)
{
__be32 dst_ip = msg->content.in_info.in_dst_ip; struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip);
eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client);
if (eg_entry && eg_entry->shortcut) { if (eg_entry->shortcut->qos.txtp.traffic_class &
msg->qos.txtp.traffic_class &
(qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)) { if (eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR)
entry->shortcut = eg_entry->shortcut; elseif (eg_entry->shortcut->qos.txtp.max_pcr > 0)
entry->shortcut = eg_entry->shortcut;
} if (entry->shortcut) {
dprintk("(%s) using egress SVC to reach %pI4\n",
client->dev->name, &dst_ip);
client->eg_ops->put(eg_entry); return;
}
} if (eg_entry != NULL)
client->eg_ops->put(eg_entry);
/* No luck in the egress cache we must open an ingress SVC */
msg->type = OPEN_INGRESS_SVC; if (qos &&
(qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class)) {
msg->qos = qos->qos;
pr_info("(%s) trying to get a CBR shortcut\n",
client->dev->name);
} else
memset(&msg->qos, 0, sizeof(struct atm_qos));
msg_to_mpoad(msg, client);
}
entry->ctrl_info = msg->content.in_info;
entry->time = ktime_get_seconds(); /* Used in refreshing func from now on */
entry->reply_wait = ktime_get_seconds();
entry->refresh_time = 0;
ddprintk_cont("entry->shortcut = %p\n", entry->shortcut);
sk = sk_atm(vcc);
skb_queue_tail(&sk->sk_receive_queue, skb);
sk->sk_data_ready(sk);
dprintk("exiting\n");
}
/* * Our MPS died. Tell our daemon to send NHRP data plane purge to each * of the egress shortcuts we have.
*/ staticvoid mps_death(struct k_message *msg, struct mpoa_client *mpc)
{
eg_cache_entry *entry;
/* FIXME: This knows too much of the cache structure */
read_lock_irq(&mpc->egress_lock);
entry = mpc->eg_cache; while (entry != NULL) {
purge_egress_shortcut(entry->shortcut, entry);
entry = entry->next;
}
read_unlock_irq(&mpc->egress_lock);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.