If Iran is attacked then Pakistan needs to be thinking, what is next? Given that US/NATO is after central Asian resource, without Pakistani territory/port it will be expensive for these resource to go somewhere. Therefore, it is obvious Pakistan will be target one way or another, sooner or later. Heck Pakistan is already facing attack (if not full fledge war) from many fronts already. It is natural Pakistan would want to keep these imperialist out of the country. But the way game is IMPOSED only way Pakistan can keep these imperialists out of the country by keeping them out of the region.
Pakistan can coordinate its strategic, political and defense move with Iran and SCO to ward off these invaders. And Pakistan does not need to be explicit, lot can be done when Pakistan enjoys border with Iran.